它是一个简单的三行代码,我无法理解错误。
(我试图从python创建一个json文件,然后从中读取和写入。
注意:每次运行此代码时都会创建hi.json
,但随后出现错误。我已经尝试了.loads和.load函数。)
代码:
import json
with open("hi.json","a+") as f:
d=f.read()
d3=json.loads(d)
错误:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File"C:\Users\minusv\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads return _default_decoder.decode(s)
File"C:\Users\minusv\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File"C:\Users\minusv\AppData\Local\Programs\Python\Python36\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)