我有一個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