Это похоже на то, что вы хотите:)
results = json.load(googleResponse)['results']
for result in results:
for address_component in result['address_components']:
if address_component['types'] == ['locality', 'political']
# address_component['long_name'] and
# address_component['short_name'] are your data
break
Крутая вещь о JSON и Python диктует , что вам не нужно индексировать по номеру, вы индексируете по имени. В этом случае ваш объект (или, по крайней мере, данные, которые вас интересуют) разбивается следующим образом:
'results': # a list of resulting dicts
[
{ # one of those resulting dicts
'address_components': # a key, representing some other data
[ # which, in this case, is a list of address component dicts
{ # like this
'long_name': 'A String. The Long Name.'
'short_name': 'Another String. The Short Name.'
'types': # a list of type strings
[
'locality', # one of the types
'political' # the other type
]
}
]
}
]