I'm trying to use simplejson to parse a request from the ustream data api, and I get this error when decoding. I'm new to the json library in python, so i'm not sure where to begin working towards a solution.
>>> 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
any help?
When doing this :
>>> in_json = None
>>> json.loads(in_json)
you ask json to parse None
... and None is not a JSon object, that's the cause of your problem.
I think it would be better to do something like this
>>> r = requests.get("http://api.ustream.tv/json/stream/popular/search/all?key=y
ourDevKey")
>>> json.loads(r.content)