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.
I need to extract all the values ββof [aaaa|yyyy|zzz].categories.analysis . That is, I need to specify Dictionary<string, string> the object name (for example, Abbbb , Acccc , etc.) and the identifier, ignoring the name string.
eg., [Abbbb, 9001] [Acccc, 9001] [Adddd, 9001] ... [Zaaaa, 9001]
I have been too long and feel that I am missing something obvious. I tried JSON.net and my own serialization. This is a trivial task in all other languages ββthat I used.
I came close to something like this:
var ajsonObject = JsonConvert.DeserializeObject<dynamic>(jsonString); var oasearch_categories = ajsonObject.aaaa.categories.analysis;
But then again, aaaa can be any string, so I'm not sure how to dynamically refer.