读json,重复小组

时间:2012-05-24 12:02:28

标签: json windows-phone-7

我正在尝试制作一个从网站上读取json文件的Windows Phone应用程序。这个json文件有一个重复组,我似乎无法让程序读取所有组。

这是json输出的一个例子:

{
    "program":{
        "title":"Carl Schmitz",
        "image_url":"http:\/\/q-music.be\/sites\/2009.q-music.be\/files\/NOA.jpg"
    },
    "noa":[
        {
            "title":"Behind Blue Eyes",
            "artist":"LIMP BIZKIT",
            "itunes_link":"http:\/\/clk.tradedoubler.com\/click?p=24379&a=1256924?url=http:\/\/itunes.apple.com\/be\/album\/behind-blue-eyes\/id14915153?i=14915155&uo=4&partnerId=2003"
        },
        {
            "title":"Alone Again",
            "artist":"ALYSSA REID",
            "itunes_link":"http:\/\/clk.tradedoubler.com\/click?p=24379&a=1256924?url=http:\/\/itunes.apple.com\/be\/album\/alone-again-original-mix\/id496520410?i=496520415&uo=4&partnerId=2003"
        }
    ]
}

有人能解释我怎么读这个json吗?

1 个答案:

答案 0 :(得分:1)

你的类结构看起来应该是这样的。我用了很棒的json2csharp来生成它:

然后您应该能够直接反序列化到RootObject中。您没有提到您正在使用的序列化程序,因此此处(尚未)未显示实际的反序列化。

public class Program
{
    public string title { get; set; }
    public string image_url { get; set; }
}

public class Noa
{
    public string title { get; set; }
    public string artist { get; set; }
    public string itunes_link { get; set; }
}

public class RootObject
{
    public Program program { get; set; }
    public List<Noa> noa { get; set; }
}
相关问题