【问题标题】:Parse JSON with newtonsoft使用 newtonsoft 解析 JSON
【发布时间】:2012-06-29 23:30:08
【问题描述】:

我正在从这个 google api 服务获取 json 响应,以获取经纬度的反向地理位置。

http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true

在响应 JSON 中有很多相同名称的 rack []。如何使用 newtonsoft 解析这个 JSON 以获取国家/地区名称。

【问题讨论】:

标签: c# json windows-phone-7 json.net


【解决方案1】:
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() : "";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-16
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多