c# influxDB
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;