I'm trying to parse JSON using the json library. I'm executing the chunk of code below, and I get the error:
Traceback (most recent call last):
File "test1.py", line 12, in <module>
parsedResponse = json.loads(data)
File "/usr/local/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python2.7/json/decoder.py", line 360, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python2.7/json/decoder.py", line 378, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
The code is:
import urllib, urllib2
from django.utils import simplejson
import json
opener = urllib2.build_opener()
requestURL = "http://api.shopstyle.com/action/apiSearch?pid=2254&fts=red+dress&min=0&count=10"
data = opener.open(requestURL).read().decode('utf8')
print data #this works
parsedResponse = json.loads(data)
I tried removing the read().decode('utf8') and passing that into json.load(), but that doesn't work either. I'd appreciate any help :)
Thanks.
print data? It sounds like what you're receiving is not valid, or not properly formed.print repr(data)(don't do justprint data) then copy/paste it into an edit of your question.