Python Valueerror: No Json Object Could Be Decoded
Solution 1:
For me it was an encoding problem, you can try using Notepad++ to edit your .json file and change the Encoding to UTF-8 without BOM. Another thing you could check is if your json script is valid
Solution 2:
It's possible the .read()
method is moving the cursor to the end of the file. Try:
for filename in filenames:
withopen(os.path.join(dirname,filename)) as fd:
json_data = json.load(fd)
and see where that gets you.
This, of course, assumes you have valid JSON, as your example demonstrates. (Look out for trailing commas)
Solution 3:
I resolved this error by Converting the json file to UTF-8 with no BOM. Below is a python snippet and url for conversion
myFile=open(cases2.json, 'r')
myObject=myFile.read()
u = myObject.decode('utf-8-sig')
myObject = u.encode('utf-8')
myFile.encoding
myFile.close()
myData=json.loads(myObject,'utf-8')
Solution 4:
The reply suggesting that .read() was moving the cursor led to a resolution of my version of the problem. I changed
print response.read()
...
json_data = json.loads(response.read())
to
responseStr = response.read()
print responseStr
...
json_data = json.loads(responseStr)
Solution 5:
I had the same problem today. Trying to understand the cause, I found this issue related to json
module:
http://bugs.python.org/issue18958
Check if the file is UTF8 encoded and if it is the case, then use codecs
module to open and read it or just skip the BOM (byte order mark).
Post a Comment for "Python Valueerror: No Json Object Could Be Decoded"