influxDB 0.9 C# 讀寫類
WebClient client 中文是亂碼 返回中文是亂碼
第一次嘗試:
string question = textBox1.Text.ToString();
WebClient youdao = new WebClient();
youdao.Encoding = System.Text.Encoding.GetEncoding("GB2312");
Uri uri = new Uri("http://xxxxxxxxxxxxxx");
textBox1.Text =youdao.DownloadString(uri);
返回的字符串中有中文,出現亂碼
嘗試n次后,解決辦法如下:
string question = textBox1.Text.ToString();
WebClient youdao = new WebClient();
youdao.Encoding = System.Text.Encoding.GetEncoding("GB2312");
Uri uri = new Uri("http://xxxxxxxxxxxxxx");
textBox1.Text =Encoding.UTF8.GetString(youdao.DownloadData(uri));
先獲取最基本的byte[]類型返回數據,然后轉碼成UTF8即可
————————————————
版權聲明:本文為CSDN博主「updownlife」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/updownlife/article/details/7624179
string result = string.Empty; WebClient client = new WebClient(); client.Encoding = System.Text.Encoding.GetEncoding("GB2312"); if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { client.Credentials = GetCredentialCache(uri, username, password); client.Headers.Add("Authorization", GetAuthorization(username, password)); } return Encoding.UTF8.GetString(client.DownloadData(uri));
JObject jo = new JObject(); // jo = (JObject)JsonConvert.DeserializeObject(clientCZ.Query("SELECT weight FROM car where furnace='"+ unitName + "' GROUP BY port order by time desc limit 1")); jo = (JObject)JsonConvert.DeserializeObject(client.Query("steel", "SELECT weight FROM car WHERE furnace ='"+unitName+"%23高爐' GROUP BY port order by time desc limit 1 ")); JArray jArray = new JArray(); if (jo != null) { JArray ja = JArray.Parse(jo["results"].ToString()); for (int i = 0; i < ja.Count; i++) { JObject joResult = JObject.Parse(ja[i].ToString()); if (joResult["series"] != null) { JArray jaSeries = JArray.Parse(joResult["series"].ToString()); for (int j = 0; j < jaSeries.Count; j++) { jArray = (JArray)jaSeries[i]["values"]; } } } } return jArray;