0
我使用Google Places Reverse Geocode API返回给定地址的纬度和长度。该API返回一个庞大的JSON文件,其中包含大量嵌套对象。这里是Google的documentation。Python/Django引用嵌套JSON
我想抓住geometry.location.lat对象(请参阅文档)。这里是我当前的代码,然后它会返回错误:
address_coords = gmaps.geocode(raw_address)
# gmaps makes the API request and returns the JSON into address_coords
address_lat = address_coords['results']['geometry']['location']['lat']
address_lon = address_coords['results']['geometry']['location']['lng']
TypeError: List indices must be integers or slices, not str
我不知道如何引用JSON对象。
您应该显示您尝试访问的数据。如错误所述,该数据结构的至少一个级别是列表而不是字典。 –