I am trying to parse a JSON response that includes something that I am not completely familiar with, and I have not seen in the wild that often.
Inside one of the JSON objects there is a JSON object with a dynamic name.
In this example, there is a JSON object inside "bugs"with a name "12345"that correlates with the error number.
{
"bugs" : {
"12345" : {
"comments" : [
{
"id" : 1,
"text" : "Description 1"
},
{
"id" : 2,
"text" : "Description 2"
}
]
}
}
}
I'm wondering: What would be the most efficient way to parse a JSON object with a dynamic name?
For some JSON Utility tools, such as
They will take the JSON response as the one above and convert it to classes as follows:
jsonutils
public class Comment
{
public int id { get; set; }
public string text { get; set; }
}
public class 12345
{
public IList<Comment> comments { get; set; }
}
public class Bugs
{
public 12345 12345 { get; set; }
}
public class Root
{
public Bugs bugs { get; set; }
}
json2charp
public class Comment
{
public int id { get; set; }
public string text { get; set; }
}
public class __invalid_type__12345
{
public List<Comment> comments { get; set; }
}
public class Bugs
{
public __invalid_type__12345 __invalid_name__12345 { get; set; }
}
public class RootObject
{
public Bugs bugs { get; set; }
}
, class . , API , [JsonProperty("")], .
, JSON , JSON, . , JSON API, , ?