0

I am trying to get this return:

Google API

Into a Python iterable object

So far I have this:

request = "http://maps.googleapis.com/maps/api/geocode/%s?address=%s&sensor=%s" % (self._output, self._address, self._sensor)
data = urllib.urlopen(request).read()
decoded_data = json.loads('[%s]' % data).pop()
    if decoded_data.get("status") == "OK":
        return decoded_data
    return ""

However this only turns the outer "wrapper" into a dictionary. I want to decode the entire block so I can access the values easily and raise exceptions where needed.

4

1 に答える 1

3

なぜあなたはそれをリストにまとめているのですか?これは JSON オブジェクトであり、Python ディクショナリに非常にきれいにマップされます。するだけでdecoded_data = json.loads(data)、次のことができますdecoded_data['results'][0]['formatted_address']

于 2012-04-24T11:50:50.310 に答える