I\'m trying to parse a JSON response that includes something I\'m not quite familiar with, nor have I seen in the wild that often.
Inside one of the JSON ob
Newtonsoft.Json JsonConvert can parse it as a Dictionary
provided with appropriate model classes:
public class Comment
{
public int id { get; set; }
public string text { get; set; }
}
public class Comments
{
public List comments { get; set; }
}
public class RootObject
{
public Dictionary bugs { get; set; }
}
That can be checked with:
var json = "{\r\n \"bugs\" : {\r\n \"12345\" : {\r\n \"comments\" : [\r\n {\r\n \"id\" : 1,\r\n \"text\" : \"Description 1\"\r\n },\r\n {\r\n \"id\" : 2,\r\n \"text\" : \"Description 2\"\r\n }\r\n ]\r\n }\r\n }\r\n}";
Console.WriteLine(json);
var obj = JsonConvert.DeserializeObject(json);
Console.WriteLine(obj.bugs["12345"].comments.First().text);