I'm trying to populate a JSON/XML string into C# object. I convert my XML to JSON and then use JSON.NET. Example:
JSON string
{
"persons":[
{
"age":30,
"name":"david",
"hobbies":[
{
"name":"tennis",
"hours":5
},
{
"name":"football",
"hours":10
}
]
},
{
"name":"adam",
"age":23,
"hobbies":[]
}
]
}
C# Classes
public class Hobbies
{
public string name;
public int hours;
}
class Person
{
public string name;
public int age;
public List<Hobbies> hoobies = new List<Hobbies>();
}
I'm trying to populate the data into a list of persons:
List<Person> persons = new List<Person>();
JsonConvert.PopulateObject(myJsonText, persons);
and I'm getting this exception:
Cannot populate JSON object onto type
How can I do that?