我有一个JSON文件夹结构,需要反序列化为一个c#对象。我想知道如何在不设置多个子类对象的情况下做到这一点(因为可能有大量的子文件夹)。我在想也许一个继承父对象的子对象,或者有一个包含它自己的对象可能是要走的路,但我很难过!将JSON文件夹结构反序列化为C#对象
干杯!
JSON结构:
[
{
type: "folder",
name: "animals",
path: "/animals",
children: [
{
type: "folder",
name: "cat",
path: "/animals/cat",
children: [
{
type: "folder",
name: "images",
path: "/animals/cat/images",
children: [
{
type: "file",
name: "cat001.jpg",
path: "/animals/cat/images/cat001.jpg"
}, {
type: "file",
name: "cat001.jpg",
path: "/animals/cat/images/cat002.jpg"
}
]
}
]
}
]
}
]
Json2CSharp输出:
public class Child3
{
public string type { get; set; }
public string name { get; set; }
public string path { get; set; }
}
public class Child2
{
public string type { get; set; }
public string name { get; set; }
public string path { get; set; }
public List<Child3> children { get; set; }
}
public class Child
{
public string type { get; set; }
public string name { get; set; }
public string path { get; set; }
public List<Child2> children { get; set; }
}
public class RootObject
{
public string type { get; set; }
public string name { get; set; }
public string path { get; set; }
public List<Child> children { get; set; }
}
谢谢!这帮助了我的问题! – jessemillman 2014-09-24 10:17:38