Please help me to parse array from this json in C#:
{
"error_code":0,
"response":
{
"17":
{
"id":"17","name":"Books"
},
"21":
{
"id":"21","name":"Movies"
},
"13":
{
"id":"13","name":"Cafe"
},
"5":
{
"id":"5","name":"Music"
},
"49":
{
"id":"49","name":"Theatres"
}
}
}
I'm using the Newtonsoft.Json library
That's not a JSON array - it's just a JSON object which happens to have numbers for the properties of the response
object.
You can parse it as a JObject
, or deserialize it to a class like this:
public class Root
{
public int ErrorCode { get; set; }
public Dictionary<string, Entry> Response { get; set; }
}
public class Entry
{
public string Id { get; set; }
public string Name { get; set; }
}
...
Root root = JsonConvert.DeserializeObject<Root>(json);
See more on this question at Stackoverflow