When dealing with the local JSON file, because of the change of the JSON format, the code can not run and the error occurs. Here are the solutions:
[initial code]
with open(path,'r') as f:
a = json.loads(f.read())
print(a)
print(type(a))
[prompt error]
Traceback (most recent call last):
File "C:\Users\14062\Desktop\json02.py", line 25, in <module>
c = json.loads(b)
File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\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)
[solution]
with open(path,encoding='utf-8-sig', errors='ignore') as f:
data = json.load(f, strict=False)
print(data)
Similar Posts:
- [Solved] json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Python: json:json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19)
- Python JSON error json.decoder.jsondecodeerror Chinese
- [Solved] TypeError: string indices must be integers, not str
- TypeError: the JSON object must be str, not ‘bytes’
- Python Open File SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in …
- python3 are installed through pip on Win 10, Unicode decodeerror: ‘UTF-8’ codec can’t decode byte
- How to Solve Python Error: “HTTP Error 403: Forbidden”
- Error in reading Chinese path of pydev in eclipse
- [Solved] JSON check syntax error: json.decoder.JSONDecodeError: Invalid control character at: line 1 column