import httplib
try:
import json
except ImportError: # for Python 2.5
import simplejson as json
path = ('/maps/geo?q=207+N.+Defiance+St%2C+Archbold%2C+OH'
'&output=json&oe=utf8')
connection = httplib.HTTPConnection('maps.google.com')
connection.request('GET', path)
rawreply = connection.getresponse().read()
reply = json.loads(rawreply)
print reply['Placemark'][0]['Point']['coordinates'][:-1]
结果是
Traceback (most recent call last):
File "E:/Program Files (x86)/python2.7.3/来了", line 13, in <module>
print reply['Placemark'][0]['Point']['coordinates'][:-1]
KeyError: 'Placemark'
没懂额,要怎么操作啊?
怎样改啊
追答梦未央说明了啊。问他吧。 目前你的响应里没有'Placemark'这个键 。所以程序走不下去。 可能是少了一步,也可能是没有认证。我自己没有试过。不能给你直接的答案。你再试试。
你在reply = json.loads(rawreply)的后面加一句
print dir(reply)
print reply
这样就知道你怎么去尝试了。
求教怎么改?