解析 JSON 文件但未返回所有内容
Parsing a JSON file but not getting everything returned
我正在尝试从 Google 个位置 API 解析一个 JSON 文件。我正在尝试收集附近地址、lng/lat 坐标以及地点 ID。在包含 JSON 文件的页面上,我的代码正在捕获更多位置信息,但由于某种原因,它没有从其中一个位置获取数据。我的代码是:
response = urllib.urlopen(url)
data = json.loads(response.read())
for n in range(len(data['results'])):
location = []
address = data['results'][n]['vicinity']
address = address[: address.find(", ")]
coords_lat = str(data['results'][n]['geometry']['location']['lat'])
coords_lat = coords_lat[:-4]
coords_lng = str(data['results'][n]['geometry']['location']['lng'])
coords_lng = coords_lng[:-4]
place_id = data['results'][n]['place_id']
location = [address, coords_lat, coords_lng, place_id]
print location
但是对于其中一个位置,我的程序正在返回:
...[u'C', '33.87', '-84.53', u'ChIJOUmV_jgX9YgRdN1sudI8yOI']...
而不是此位置的完整附近地址,'C, 2976 Ask-Kay Dr, Smyrna'
。
This is my python program
This is the API JSON page with one of the results I'm referring to
These are some of the lines my program is printing
您可能希望在
之后立即显示 address
address = data['results'][n]['vicinity']
在使用
编辑之前
address = address[: address.find(", ")]
可能与文中的,
个字符有关
C, 2976 Ask-Kay Dr, Smyrna
我正在尝试从 Google 个位置 API 解析一个 JSON 文件。我正在尝试收集附近地址、lng/lat 坐标以及地点 ID。在包含 JSON 文件的页面上,我的代码正在捕获更多位置信息,但由于某种原因,它没有从其中一个位置获取数据。我的代码是:
response = urllib.urlopen(url)
data = json.loads(response.read())
for n in range(len(data['results'])):
location = []
address = data['results'][n]['vicinity']
address = address[: address.find(", ")]
coords_lat = str(data['results'][n]['geometry']['location']['lat'])
coords_lat = coords_lat[:-4]
coords_lng = str(data['results'][n]['geometry']['location']['lng'])
coords_lng = coords_lng[:-4]
place_id = data['results'][n]['place_id']
location = [address, coords_lat, coords_lng, place_id]
print location
但是对于其中一个位置,我的程序正在返回:
...[u'C', '33.87', '-84.53', u'ChIJOUmV_jgX9YgRdN1sudI8yOI']...
而不是此位置的完整附近地址,'C, 2976 Ask-Kay Dr, Smyrna'
。
This is my python program
This is the API JSON page with one of the results I'm referring to
These are some of the lines my program is printing
您可能希望在
之后立即显示address
address = data['results'][n]['vicinity']
在使用
编辑之前address = address[: address.find(", ")]
可能与文中的,
个字符有关
C, 2976 Ask-Kay Dr, Smyrna