![HttpWebRequest:百度定位当前位置解析 HttpWebRequest:百度定位当前位置解析](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create("http://api.map.baidu.com/location/ip?ak=F857f4c4f2600cb213e791ca265b7626"); HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream s = response.GetResponseStream(); string strJson = ""; using (TextReader reader = new StreamReader(s)) { Newtonsoft.Json.Linq.JObject jb = JsonConvert.DeserializeObject(strJson) as Newtonsoft.Json.Linq.JObject; Newtonsoft.Json.Linq.JToken result; if (!jb.TryGetValue("status", out result)) { return; } ") //0:正常 { LocateStar.city = jb.SelectToken("content.address_detail.city").ToString(); API.WriteINI("LocateStar", "UserCity", LocateStar.city, commonclass.config); }