I was researching during a lot of time about how deserialize this json file:
{
"clients":[
{
"id":"a0ece5db-cd14-4f21-812f-966633e7be86",
"name":"Britney",
"email":"[email protected]",
"role":"admin"
},
{
"id":"e8fd159b-57c4-4d36-9bd7-a59ca13057bb",
"name":"Manning",
"email":"[email protected]",
"role":"admin"
},
{
"id":"a3b8d425-2b60-4ad7-becc-bedf2ef860bd",
"name":"Barnett",
"email":"[email protected]",
"role":"user"
[ ... ]
This is my controller code:
using (var sr = new StreamReader(response.GetResponseStream()))
{
receivedData = sr.ReadToEnd();
}
var userList = JsonConvert.DeserializeObject<List<User>>(receivedData);
foreach (User us in userList)
{
//this method just print the user Id
MsgBox(u.Id);
}
So, I am absolutely stuck because the Json
JsonConvert.DeserializeObject>(receivedData); launch the following exception:
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[InsuranceWebAPI.Models.User]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
I try to set the json data into an array and a list, but doesn't works. I know that maybe is a very beginner question but I am not used to work with Json and Json.net
Can any body help me to get the data into an array or List.
Thanks in advance to everybody and sorry if I don't understand properly the other questions about Json.net