如何在列表中解析此 json<Class>?



我正在开发windows窗体应用程序在框架4.0。我用的是JSON.NET。我有以下json字符串变量。我有json中的10个类如下所示。如何解析以下json并将其转换为List

[
        {
            "Class": 1,
            "ClassUrl": "EngineeringSemister12014A",
            "OEPTitle": "Engineer",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                }
            ],
            "IsArchived": true
        },
        {
            "Class": 7,
            "ClassUrl": "Engineer2014A",
            "OEPTitle": "Engineer",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                }
            ]
        },
        {
            "Class": 8,
            "ClassUrl": "Engineer22014A",
            "OEPTitle": "Engineer2",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                }
            ]
        },
        {
            "Class": 9,
            "ClassUrl": "Engineer32014A",
            "OEPTitle": "Engineer3",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                }
            ]
        },
        {
            "Class": 10,
            "ClassUrl": "Engineer32014B",
            "OEPTitle": "Engineer3",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                },
                {
                    "Id": 8,
                    "OEPTitle": "english"
                }
            ],
            "IsRecycled": true
        },
        {
            "Class": 12,
            "ClassUrl": "Engineer52014B",
            "OEPTitle": "Engineer5",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                },
                {
                    "Id": 8,
                    "OEPTitle": "english"
                }
            ]
        },
        {
            "Class": 13,
            "ClassUrl": "Engineer62014B",
            "OEPTitle": "Engineer6",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                },
                {
                    "Id": 8,
                    "OEPTitle": "english"
                }
            ]
        },
        {
            "Class": 16,
            "ClassUrl": "Mechanical2014undefined",
            "OEPTitle": "Mechanical Branch",
            "Subject": [
                {
                    "Id": 6,
                    "OEPTitle": "history"
                },
                {
                    "Id": 4,
                    "OEPTitle": "chemical "
                }
            ]
        },
        {
            "Class": 6,
            "ClassUrl": "Engineer12014A",
            "OEPTitle": "Engineer1",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                },
                {
                    "Id": 6,
                    "OEPTitle": "history"
                },
                {
                    "Id": 4,
                    "OEPTitle": "chemical "
                }
            ]
        },
        {
            "Class": 11,
            "ClassUrl": "Engineer42014B",
            "OEPTitle": "Engineer4",
            "Subject": [
                {
                    "Id": 1,
                    "OEPTitle": "Algebra"
                },
                {
                    "Id": 2,
                    "OEPTitle": "Maths"
                },
                {
                    "Id": 6,
                    "OEPTitle": "history"
                },
                {
                    "Id": 4,
                    "OEPTitle": "chemical "
                },
                {
                    "Id": 8,
                    "OEPTitle": "english"
                }
            ]
        }
    ]

使用 json2csharp :

public class Subject
{
    public int Id { get; set; }
    public string OEPTitle { get; set; }
}
public class RootObject
{
    public int Class { get; set; }
    public string ClassUrl { get; set; }
    public string OEPTitle { get; set; }
    public List<Subject> Subject { get; set; }
    public bool IsArchived { get; set; }
}

,现在可以使用JSON了。净:

List<RootObject> rootObj = JsonConvert.Deserialize<List<RootObject>>(yourJsonHere);

相关内容

  • 没有找到相关文章

最新更新