如何在C#中访问此JSON值

时间:2017-03-11 12:51:43

标签: c# json parsing json.net mapquest


我有这个JSON数据,我需要在C#中获得一些特定的值。

long double

我已经使用过JSON.NET,并知道我必须首先反序列化它。但我不知道如何获得“lat”和“lng”值。在我的情况下,我将得到所有这三个并比较它们。

2 个答案:

答案 0 :(得分:1)

首先按照我的回答here中的步骤创建C#类来模仿JSON结构的结构。

然后只需这样做:

Glide.with(this).load("http://cfile2.uf.tistory.com/image/114DCE3E4D6456E52E6A5F").into(imageView);
Glide.with(this).pauseRequests();

答案 1 :(得分:1)

您不必创建代表您的JSON数据的类。你可以query into JSON这样:

var json = File.ReadAllText("ex.json");
var jobject = JObject.Parse(json);
var results = jobject["results"];
foreach (var result in results)
{
    var locations = result["locations"];
    foreach (var location in locations)
    {
        var pair = location["latLng"];
        Console.WriteLine("Lat: {0}, Lng: {1}", pair["lat"], pair["lng"]);
    }
}