C# 读取Json内的数据,中文乱码,如何解决?
我把代码贴出来,大家看看!
这是网上找的一段代码
private string getJson()
{
string url="http://218.228.332.114:8089/order/xxxxxx?prodid=330006";
string addressBookStr1 = null;//存放整个的字符串
HttpWebRequest addressRequest;//
HttpWebResponse addressResponse;//请求回应
try
{
addressRequest = (HttpWebRequest)WebRequest.Create(url);
addressRequest.Method = "GET";
addressResponse = (HttpWebResponse)addressRequest.GetResponse();
string t = addressResponse.ContentType;
string c = addressResponse.ContentEncoding;
Stream addressStream = addressResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(addressStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
String str = "";
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
str = new String(read, 0, count);
addressBookStr1 += str;
count = readStream.Read(read, 0, 256);
}
readStream.Close();
addressStream.Close();
addressResponse.Close();
}
catch
{
return null;
}
return addressBookStr1;
}