在Python中加载JSON文件错误

时间:2017-03-07 18:13:21

标签: python json

我正在尝试学习如何从Python中读取json文件,我不知道如何解释我收到的错误我已经在下面发布了我的代码以及我收到的错误消息。有任何想法吗?谢谢!

import json
filename = 'population.json'
with open(filename) as f:
    pop_data = json.load(f)
for pop_dict in pop_data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
    population = pop_dict['Value']
    print(country_name + ":" + population)

错误消息----

C:\Anaconda\python.exe "C:/PyCharm/Data Visual/Pop.py"
Traceback (most recent call last):
  File "C:/PyCharm/Data Visual/Pop.py", line 4, in <module>
    pop_data = json.load(f)
  File "C:\Anaconda\lib\json\__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Anaconda\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Anaconda\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Anaconda\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Process finished with exit code 1

0 个答案:

没有答案