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對象。
您應該顯示您嘗試訪問的數據。如錯誤所述,該數據結構的至少一個級別是列表而不是字典。 –