GoogleMaps APIからJSON応答を解析して、入れ子になったdictの値をPandas DataFrameに読み込もうとしています。 JSONレスポンスの構造を以下に示します。GoogleMaps API JsonはPythonでijsonを使用して解析します
( 'types'、 'short_name'、 'long_name')を列ヘッダーとして使用し、各アドレスクエリのそれぞれの値を行として 'address_components'というDataFrameを作成しようとしています。私はijson使用しようとした
:
from ijson import items
import ijson
f = urlopen('https://maps.googleapis.com/maps/api/geocode/json?address=2022+Boren+Ave%2C+Seattle+98101')
objects = list(ijson.items(f, 'results.address_components'))
objects
アウト:[]
私の問題は、成功した、ネストされたdictsを横断しています。
また、GoogleMaps GeoLocator API DocumentationとGoogleMaps JSON parsing docsも確認しました。 This solution seems to solve the problem, but on IOS
そのため私は巣に到達するために貢献していない...
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
ファンタスティック!どうもありがとうございます。これはまさに私が探していたものです。明らかに、私はまだ私が私の質問に信頼できる回答者ではなかったことを私に言った箱をチェックしたときのように公式に言うことができません...いずれにせよ、非常にありがとう。 –