Consuming an external service where they decided to provide an object as an array where each property is on a fixed position. Like
{
"persons" : [
["Luck", "Lucky", 28],
["Joe", "Dalton", 30],
["Jack", "Dalton", 28],
["William", "Dalton", 26],
["Averell", "Dalton", 24]
]
}
I would like to deserialize this to a List of Person.
var persons = JsonConvert.DeserializeObject<Person[]>(json);
class Person {
public string FirstName {get; set; }
public string LastName {get; set; }
public int Age{get; set; }
}
Is there an easy way (property annotation) to do this, or will it come down to write a custom serialiser?
Since most answers are missing the essence of the question.
This would have been easy if
{
"persons" : [
{
"FirstName" : "Luck",
"LastName" : "Lucky",
"Age" : 28
},
// ...
]
}
But that is not the case.