Deserializing JSON

I have a string array with multiple JSON and the only way to make it work looks to be like this:

public void method(string [] data) { foreach(var item in data) { var theData = JsonConvert.DeserializeObject<List<SampleObject>>(item); } } 

The problem with this is that each time I do this the list loses the previous data and creates a new list for the next set of data.

The Json looks like this:

"[{\"Birthdate\":\"1947-03-21\",\"Gender\":\"M\",\"Grade\":\"10\"}]" 

It is a little longer than that and I can't change the way it is coming into the method.

SampleObject looks like this:

public class SampleObject { public string Birthdate{ get; set; } public string Gender{ get; set; } public string Grade{ get; set; } } 

Is there any way to make this work so that I can have the data separated in the list?

by Hi_Energy via /r/csharp

Leave a Reply