/// <summary>
/// get http请求获取位置信息
/// </summary>
internal void getRequestCity()
{
String url = "https://route.showapi.com/238-2?from=5&lat=39.9229&lng=116.4629&api_id=26&api_s=19e4d";
try
{
var wc = new WebClient();
wc.Encoding = System.Text.Encoding.UTF8;
//wc.OpenRead("https://route.showapi.com");
var data = wc.DownloadString(url);
//一下代码是我简单写的解析
string[] mArray = data.Split(',');
for (int i = 0; i < mArray.Length; i++)
{
string []arry= mArray[i].Split(':');
if (arry[0].Equals("\"city\""))
{
city = arry[1].Split('"')[1];
}
if (arry[0]== "\"district\"")
{
district = arry[1].Split('"')[1];//取district
break;
}
}
}
catch
{
//通知主线程
return;
}
//通知主线程
}
c# post请求 返回json处理
最新推荐文章于 2024-08-08 20:28:25 发布