I have an API that I am calling that returns back a set of JSON. This one in particular is to return a set of Projects to me. These projects can have multiple sub-projects. The structure is the same for all of the sub-projects as it is the main projects. I can't seem to find anything that shows me how to parse the JSON so that it gives me some sort of usable class in .NET so I can show it on my web page.
Here is the structure (condensed because the original is HUGE and renamed projects and numbers to make it easier to read):
{
"data": [
{
"id": 70000,
"name": "Project 70000",
"children": [
{
"id": 71000,
"name": "Project 71000",
"children": [
{
"id": 71100,
"name": "Project 71100",
"children": [
{
"id": 71110,
"name": "Project 71110",
"children": [
{
"id": 71111,
"name": "Project 71111"
},
{
"id": 71112,
"name": "Project 71112"
}
]
}
]
}
]
}
]
},
{
"id": 80000,
"name": "Project 80000",
"children": [
{
"id": 81000,
"name": "Project 81000"
}
]
}
]
}
What I think I want my class to look like (I may be wrong here) is this:
public class data
{
public List<project> { get; set; }
}
public class project
{
public int id { get; set; }
public string name { get; set; }
public List<project> children { get; set; }
}
I am using JSON.NET but anything I've tried winds up not doing anything or leaves me with errors in which I cannot build the project. I've used JSON.NET in the past when there was a defined structure, but this one is throwing me for a loop!