[英]Parse JSON with newtonsoft
我正在從此Google API服務獲取json響應,以獲取經緯度和緯度的反向地理位置。
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true
在響應JSON中,有很多相同名稱的rack []。 我如何使用newtonsoft解析此JSON以獲取國家/地區名稱。
WebClient wc = new WebClient();
var json = (JObject)JsonConvert.DeserializeObject(wc.DownloadString(url));
var country = json["results"]
.SelectMany(x => x["address_components"])
.FirstOrDefault(t => t["types"].First().ToString() == "country");
var name = country!=null ? country["long_name"].ToString() : "";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.