0

我正在尝试从 MapquestAPI 以 JSON 格式获取响应。使用相同的 URL,我可以从 bash 调用时得到结果

wget -q -O - "http://www.mapquestapi.com/geocoding/v1/batch?key=F20%2C7a%3Do5-hrtl1&callback=renderBatch&json=%7B%27locations%27%3A+%5B%7B%27street%27%3A+%2711880+San+Pablo+Ave%2C+El+Cerrito%27%7D%2C+%7B%27street%27%3A+%271780+E+Buena+Vista+Dr%2C+Orlando%27%7D%2C+%7B%27street%27%3A+%2714+Greenway+Circle%2C+Sacramento%27%7D%2C+%7B%27street%27%3A+%27160+Kingsland+St%2C+Nutley%27%7D%2C+%7B%27street%27%3A+%27816+Western+Ave%2C+Glen+Ellyn%27%7D%5D%7D,options:{thumbMaps:false}}"

这样做时python方式:

import urllib2, urllib
import json    

url = "http://www.mapquestapi.com/geocoding/v1/batch?key=Fmjtd%7Cluua2dua20%2C7a%3Do5-hrtl1&callback=renderBatch&json=%7B%27locations%27%3A+%5B%7B%27street%27%3A+%2711880+San+Pablo+Ave%2C+El+Cerrito%27%7D%2C+%7B%27street%27%3A+%271780+E+Buena+Vista+Dr%2C+Orlando%27%7D%2C+%7B%27street%27%3A+%2714+Greenway+Circle%2C+Sacramento%27%7D%2C+%7B%27street%27%3A+%27160+Kingsland+St%2C+Nutley%27%7D%2C+%7B%27street%27%3A+%27816+Western+Ave%2C+Glen+Ellyn%27%7D%5D%7D,options:{thumbMaps:false}}"
print url

data        =  json.dumps([1,2,3])
req         = urllib2.Request(url, data, {'Content-Type': 'application/json'})
f           = urllib2.urlopen(req)
response    = f.read

print f.read

这是结果

 <bound method _fileobject.read of <socket._fileobject object at 0x1a41bd0>>

任何建议如何在 PY 中获取 JSON 输出?

4

0 回答 0