I have data from openWeather in JSON format which gives the error
Traceback (most recent call last):
File "testjson.py", line 7, in <module>
data = json.load(data_file)
File "E:\Program Files\Python27\lib\json\__init__.py", line 290, in load
**kw)
File "E:\Program Files\Python27\lib\json\__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "E:\Program Files\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "E:\Program Files\Python27\lib\json\decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
I have run the JSON data through JSONlint and it's OK. This is it
{"city":{"id":7839581,"name":"Gold Coast","coord":{"lon":153.36055,"lat":-27.97851},"country":"AU","population":0,"sys":{"population":0}},"cod":"200","message":0.0184,"cnt":40,"list":[{"dt":1488844800,"main":{"temp":297.46,"temp_min":297.12,"temp_max":297.46,"pressure":1019.12,"sea_level":1025.73,"grnd_level":1019.12,"humidity":100,"temp_kf":0.34},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":5.16,"deg":203.005},"rain":{}}]}
and lastly my Python code
import json
from pprint import pprint
with open('weather.json') as data_file:
data = json.load(data_file)
pprint(data)
I've been messing with this for hours, chasing up leads here and anywhere else the searching takes me. Unlike a lot of more subtle errors, this just seems to be rejecting the whole lot, and I don't know why
Could anyone shed some light on this ?
json.loads, so you might want to actually do as = data_file.read(), then print it out and see that the contents of theweather.jsonis actually what you think it was.