I have the following JSON:
{
"aaaa": {
"name": "General Name",
"product": "book",
"host": "book.example.com",
"chapters": {
"bbbb": {
"name": "Chapter 1",
"page": "1",
"end_page": "25"
}
},
"categories" : {
"analysis":{
"Abbbb" : {
"name": "B Chapter",
"id" : "9001"
},
"Acccc" : {
"name": "C Chapter",
"id" : "9001"
},
"Adddd" : {
"name": "D Chapter",
"id" : "9001"
},
"Aeeee" : {
"name": "E Chapter",
"id" : "9001"
},
"Affff" : {
"name": "F Chapter",
"id" : "9001"
},
"Agggg" : {
"name": "G Chapter",
"id" : "9001"
}
},
"sources":{
"acks" : {
"name": "S. Spielberg",
"id" : "9001"
}
}
}
}
"yyyy": {
"name": "Y General Name",
"product": "Y book",
"host": "ybook.example.com",
...
}
"zzzz": {
"name": "Z General Name",
"product": "Z book",
"host": "zbook.example.com",
...
}
The values for aaaa
, yyyy
, and zzzz
can be any string and there can be any number of them.
I need to extract all of the [aaaa|yyyy|zzz].categories.analysis
values. That is, I need to end up with a Dictionary<string, string>
of the object name (e.g., Abbbb
, Acccc
, etc.) and the ID, ignoring the name
string.
E.g., [Abbbb, 9001] [Acccc, 9001] [Adddd, 9001] ... [Zaaaa, 9001]
I've been at this for way too long and feel like I'm missing something obvious. I've tried JSON.net and native serialization. This is a trivial task in every other language I've used.
I've come close with something like this:
var ajsonObject = JsonConvert.DeserializeObject<dynamic>(jsonString);
var oasearch_categories = ajsonObject.aaaa.categories.analysis;
But again, aaaa
can be any string, so I'm not sure how to reference that dynamically.