Suppose I have a json string like this:
{ … “key1″:”value1”; … }
with a key1-value1 pair somewhere deep down the json structure (which includes other things such as array, dictionary, etc…). I don’t know exactly (and don’t care) how the exact structure of the json is.
Is there a simple way to extract the “value1” ? (if there are 2 “key1” in the json string then I just need the first one).
Suppose I have a json string like this: { … key1:value1; … } with
Share
As far as I know, you have no chance of doing it manually.
If you really don’t know what’s the structure of the JSON string you’re expecting, you can try a graph search approach, such as DFS (http://en.wikipedia.org/wiki/Depth-first_search).
For every key, check if it is an array.
If so, go inside and repeat the procedure. If nothing was found in a given array, backtrack.
Interrupt your process once you have found your key.