I am a new user of Json.NET. I have created a type: Person that has different attributes: firstName, lastName, age, etc.
I have a Json string but I can't manage to deserialize it and get all the "Person" in a stored list.
Here is my piece of code I am running:
List <Person> persons = JsonConvert.DeserializeObject<List<Person>>(strPersons);`
strPersons is my json string. It is like that:
string strPersons = @"{
'Columns':['FirstName','LastName','Hobbies','Age','Country','Address','Phone','Gender'],
'Rows':[
['X', 'Y', 'Cuisine', '35', 'France', 'unknown', 'unknown', 'male'],
['W', 'Z', 'Danser', '43', 'France', 'unknown', 'unknown', 'male'],
...]
My error when compiling is:
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type System.Collections.Generic.List1[Info3JsonConvertor.Person]' because the type requires a JSON array
Can someone explain me how can I deserialize my json string to get a list
Will I have the same problem if I serialize a List<Person> into json string?
I know those questions have already been answered but if someone can explain me with my example?
strPersonsonly defines a single object, with fields ofColumnsandRows. It's not an array...Personobject that you are trying to deserialize it into. Chances are the c# object doesn't match your json object in some way. In fact you are trying to deserialize it into a list but as the error says your json object isn't an array, it is two properties, row and column. What data do you expect to actually come out of this json into your list person?Paste JSON as Classes. That will give you an object you can deserialise into.