JSON.net(newtonsoft) - 访问深层'属性'C#

时间:2012-11-13 10:22:17

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

我在Windows Phone 7.1(芒果)上使用了很棒的NewtonSoft.Json库。

我想访问Bing json答案的深层属性(红色箭头):

Bing json answer

我在resultado变量上分配了已回答的字符串,我试图这样做:

JObject o = JObject.Parse(resultado);
JsonAddress unaAddress = 
       JsonConvert
       .DeserializeObject<JsonAddress>(o["resourceSets"][0]["resources"][0].ToString());
MessageBox.Show(unaAddress.Coordinates.X);  // iexample..

但我不知道如何定义类JsonAddress以获取我需要的信息。

public class JsonAddress
{
    // public xxxx Coordinates { get; set; }
}

任何帮助?

感谢。

1 个答案:

答案 0 :(得分:0)

我找到了它:

以这种方式定义类(和子类):

public class JsonAddress
{
    public string Name { get; set; }
    public JsonPoint Point { get; set; }

}
public class JsonPoint
{
    public double[] Coordinates { get; set; }
}

以这种方式访问​​它:

MessageBox.Show(unaAddress.Point.Coordinates[0] + ", " +
                unaAddress.Point.Coordinates[1]);

感谢您的浪费时间......: - \

相关问题