i have a folder structure in JSON that i need to deserialize into a c# object. i wanted to know how i can do this without setting up multiple child class objects (as there could be a huge number of child folders). I was thinking maybe a child object that inherits the parent object, or having an object that contains itself might be the way to go but i'm stumped!
Cheers!
JSON Structure:
[
{
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 output:
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; }
}