0
我寫了一個簡單的程序來解析JSON:蟒蛇JSON解析錯誤
#! /usr/bin/env python
import urllib2
import json
so = 'https://api.stackexchange.com/2.2/users/507256?order=desc&sort=reputation&site=stackoverflow'
j = urllib2.urlopen(so)
print j.read()
j_obj = json.loads(j.read())
它失敗,並輸出如下:
Traceback (most recent call last):
File "./so.sh", line 12, in <module>
j_obj = json.loads(j.read())
File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 383, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
任何想法,我做錯了什麼?