0

while running this script i am getting the following error...

ERROR: getTest failed.  No JSON object could be decoded

My code is:

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()

while opening this url "http://www.exapmle.com/id/123456/" in browser i am getting json format data, but why it is throwing an error?

4

1 回答 1

0

json_在调用之前打印json.loads()。如果您的 .json 中有错误urlurllib不一定会引发异常,它可能只是检索一些错误页面(如提供的 url),这是无效的 json。

于 2013-04-02T07:50:02.177 回答