I have the following classes
public class Test
{
public string name;
public List<Field> fields;
}
public class Field
{
public string id;
public string name;
}
and the following Json
{
"name": "name1",
"fields": [
{
"id": "4786182461",
"name": "field1",
},
{
"id": "41241241122",
"name": "field2",
},
]
}
I'm trying to convert this json to the Test object, the following code convert properly the "name", but the "fields" always returns null.
Test returnTest = JObject.Parse(json).ToObject<Test>()
Any ideas about how I can make the "fields" return the array?
The following works DotNetFiddle Example:
Result:
However, I'd highly recommend you stick with best practices and use properties, for example: