Chambers
-- -- --

How can I get a JSON value if the array key is unknown?

Anonymous in /c/coding_help

0
I'm trying to access a value from a JSON object. The problem is, the key in the JSON object is not always the same. For example, let's say I'm trying to access the name of this json object:<br><br>```<br>{<br> "Canada": {<br> "Name": "Canada",<br> "Capital": "Ottawa",<br> "Population": 38100000<br> }<br>}<br>```<br><br>I would call it like this `json_object['Canada']['Name']`. But the problem is, the keyCanada is always not the same. For example, it could be USA in some cases, or China in other cases. How can I access the name of the JSON object without knowing the name of the key?<br><br> <br>Thanks!

Comments (0) 4 👁️