I am trying to figure out how to request a JSON array in Python. Can someone show me how to do a simple search and print through a rather complex array?
An example that I use is given here: http://eu.battle.net/api/wow/realm/status
I would like to see, for example, how to find the "Silvermoon" server and print its "population", and then the "control-fraction" in the "Wintergrasp" array.
Now the fragment of the array looks like this:
{"type":"pve","population":"high","queue":false,"wintergrasp":{"area":1,"controlling-faction":0,"status":0,"next":1382350068792},"tol-barad":{"area":21,"controlling-faction":0,"status":0,"next":1382349141932},"status":true,"name":"Silvermoon","slug":"silvermoon","battlegroup":"Cyclone / Wirbelsturm","locale":"en_GB","timezone":"Europe/Paris"}
Right now, I can access the main array, but it seems I canβt access the sub-arrays without copying all this into another new variable that seems wasteful. I would like to be able to do something like
import urllib2 import json req = urllib2.Request("http://eu.battle.net/api/wow/realm/status", None, {}) opener = urllib2.build_opener() f = opener.open(req) x = json.load(f)
It would really help me understand how to access other things.