c# post请求 返回json处理

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_41913666/article/details/83689577

 curl工具post请求       

/// <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;
      }
 //通知主线程
 }

 

展开阅读全文

没有更多推荐了,返回首页