string in webclient class c# changed to uncorrect format

流过昼夜 提交于 2020-01-06 08:03:08

问题


I call my service in wcf as you can see :

  ClientRequest.Headers["Content-type"] = "application/json";
            string result = ClientRequest.DownloadString(ServiceHostName + "/NajaService.svc/GetCarData/" + plaque);

            var javascriptserializer = new JavaScriptSerializer();
            return javascriptserializer.Deserialize<NajaResult>(result);

But the returned data is like this :

{"CarColor":"آبي سير","CarModel":"1383","CarTip":"ال ايکس","CarType":"سواري","Chassis":"83844131","Family":"####","FuelType":1,"MotorNum":"12483068683","Name":"####","NationalCode":"0000000000","Plaque":"11-426د61","PlaqueCoded":110561426,"PlaqueType":"","SystemType":"سمند","VinNo":"IRFC831V3GJ844131"}

I converted it to UTF8 byte and again convert it to utf8 string but not solved.

The encoded data is in Persian language .

I traced the request in fiddler and i found that the data is come with the correct format as you can see ,But in my code is changed


回答1:


The WebRequest contains the Encoding property you can set up before downloading the service reply. Details are here: https://msdn.microsoft.com/en-us/library/system.net.webclient.encoding(v=vs.110).aspx



来源:https://stackoverflow.com/questions/44623272/string-in-webclient-class-c-sharp-changed-to-uncorrect-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!