Reputation: 3799
I am using json.net for json object parsing. I have a string array that has of Json objects. so instead of 1 string with Json Array, I have each json object on different index of string array.
I need to de-serialize this string[] of json object into List<T>
.
If it was string of Json Array to List<T>
I would call JsonConvert.DeserializeObject<List<T>>(result);
But for this what would be the best approach to convert string[]
of jsonobject into List<T>
.
Upvotes: 0
Views: 3145
Reputation: 2594
You can do that in a very simple way using Linq :
var list = jsonobjects.Select(JsonConvert.DeserializeObject<T>).ToList();
Upvotes: 4
Reputation: 31394
You'll probably just have to call DeserializeObject
on each string in the array.
var list = new List<T>();
foreach (var jsonString in result)
list.Add(JsonConvert.DeserializeObject<T>(jsonString);
Upvotes: 2