【发布时间】:2013-01-19 01:15:12
【问题描述】:
运行此脚本时出现以下错误...
ERROR: getTest failed. No JSON object could be decoded
我的代码是:
import json
import urllib
class test:
def getTest(self):
try:
url = 'http://www.exapmle.com/id/123456/'
json_ = urllib.urlopen(url).read()
self.id = json.loads(json_)
print self.id
except Exception, e:
print "ERROR: getTest failed. %s" % e
if __name__ == "__main__":
ti = test()
ti.getTest()
在浏览器中打开此网址“http://www.exapmle.com/id/123456/”时,我正在获取 json 格式的数据,但为什么会抛出错误?
【问题讨论】:
-
您能否发布从 URL 中返回的内容以便我们查看?在这种情况下,我只能假设问题出在格式错误的 JSON 上,如果没有相关的 JSON,就很难调试。
标签: json python-2.6