我试图在Python中开始使用JSON,但似乎我误解了JSON概念中的一些东西.我按照google api示例,工作正常.但是当我在JSON响应中将代码更改为较低级别时(如下所示,我尝试访问该位置),我收到以下代码的以下错误消息:
回溯(最近一次调用最后一次):
文件"geoCode.py",第11行,在
<module>
test = json.dumps中([s ['location']为s在jsonResponse ['results']],indent = 3)KeyError:'地点'
如何在python中访问JSON文件中的较低信息级别?我是否必须转到更高级别并搜索结果字符串?这对我来说似乎很奇怪?
这是我试图运行的代码:
import urllib, json
URL2 = "http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"
googleResponse = urllib.urlopen(URL2);
jsonResponse = json.loads(googleResponse.read())
test = json.dumps([s['location'] for s in jsonResponse['results']], indent=3)
print test
Run Code Online (Sandbox Code Playgroud)