webclient类c#中的字符串更改为不正确的格式 [英] string in webclient class c# changed to uncorrect format

查看:67
本文介绍了webclient类c#中的字符串更改为不正确的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所见,我在wcf中呼叫我的服务:

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"}

我将其转换为UTF8字节,然后再次将其转换为utf8字符串,但未解决.

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

推荐答案

WebRequest包含您可以在下载服务回复之前设置的Encoding属性.详细信息在这里: https ://msdn.microsoft.com/zh-CN/library/system.net.webclient.encoding(v = vs.110).aspx

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

这篇关于webclient类c#中的字符串更改为不正确的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆