I'm trying to open and load .json file but the error appears. I'm working on windows 10.
in main the fragment of code is:
nazwapliku = nick + ".json"
losowania = czytaj_json(nazwapliku)
and the function code is:
def czytaj_json(nazwapliku):
dane = []
if os.path.isfile(nazwapliku):
with open(nazwapliku, "r") as plik:
dane = json.load(plik)
return dane
The json file is empty at the first time it start.
Traceback (most recent call last):
File "extra_lotek_f.py", line 48, in <module>
sys.exit(main(sys.argv))
File "extra_lotek_f.py", line 31, in main
losowania = czytaj_json(nazwapliku)
File "C:\Users\Comarch\Desktop\prog python\extra_lotek_mod_1.py", line 27, in czytaj_json
dane = json.load(plik)
File "C:\Python37\lib\json\__init__.py", line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "C:\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python37\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)
您的json文件不能为空,必须首先在文件内部指定[]。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.