1. 程式人生 > >c# post請求獲取json資料

c# post請求獲取json資料

        /// <summary>         /// get http請求獲取位置資訊         /// </summary>         internal void getRequestCity()         {             String url = "https://route.showapi.com/238-2?from=5&lat=39.9229&lng=116.4629&showapi_appid=28256&       showapi_sign=19eb54d";

            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;             }            //通知主執行緒         }