我正在尝试使用 simplejson 解析来自 ustream 数据 api 的请求,但在解码时出现此错误。我是 python 中的 json 库的新手,所以我不确定从哪里开始寻找解决方案。
>>> import simplejson as json
>>> import requests as requests
>>> r = requests.get("http://api.ustream.tv/json/stream/popular/search/all?key=y
ourDevKey")
>>> in_json = None
>>> json.loads(in_json)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\simplejson-2.3.0-py2.7.egg\simplejson\__in
it__.py", line 413, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\site-packages\simplejson-2.3.0-py2.7.egg\simplejson\deco
der.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
有什么帮助吗?
最佳答案
这样做时:
>>> in_json = None
>>> json.loads(in_json)
你要求 json 解析 None
... 而 None 不是 JSon 对象,这就是你的问题的原因。
我觉得这样会更好
>>> r = requests.get("http://api.ustream.tv/json/stream/popular/search/all?key=y
ourDevKey")
>>> json.loads(r.content)
关于python - 使用python从ustream api解码json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8412175/