WebClient中DownloadStringCompleted 下载的字符串,中文显示乱码
public void intiWebClient( string setstrRui)
{
//服务端返回信息后
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(setstrRui));
}
//下载之后执行的操作
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string result = e.Result;
Encoding utf8 = Encoding.UTF8;
byte[] utf8Bytes = utf8.GetBytes(result);
string dd = System.Text.Encoding.GetEncoding("gb2312 ").GetString(utf8Bytes, 0, utf8Bytes.Length);
getnewsItem = JsonConvert.DeserializeObject<NewsItem>(result);//序列化json
}
}
[解决办法]
不要设置转码,直接下载就行了哈。
[解决办法]
那你检查你下载之前的字符集是否正确。
[解决办法]
我也遇到同样问题,帮顶!!文件一般都是utf-8格式