我试图在Python中加载JSON,但总是出错
import json
f = open('StudentJson.json', 'r')
data = json.load(f)
print(data.items())
错误
Traceback (most recent call last):
File "c:\Users\Chinyere\Documents\Python\Openpyxl\students.py", line 4, in <module>
data = json.load(f)
File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line
293, in load
return loads(fp.read(),
File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我该如何处理这个错误。
2条答案
按热度按时间ds97pgxw1#
尝试像这样在json文件中输入json linting服务。它应该突出显示JSON文件的问题所在
https://jsonlint.com/
hc2pp10m2#
我的经验是,打印通过powershell控制台显示的JSON数据时会发生这种情况。事实上,如果你使用FLASK控制台本身等等。它将在那里打印数据。