I encountered a problem in my recent work. Execute JSON. Loads (JSON)_Data), in JSON_An error will be reported after adding a tab space to the data. If not, no error will be reported
1、 Json.loads (JSON)_Data) error json.decoder.jsondecodeerror: invalid control character at: line 25 column 18 (char 18)
Reason: JSON uses strict format by default, and JSON_There are illegal control symbols in the data key value, such as \ n \ T. this error is easy to report when data is passed across languages
Solution: add the parameter strict
json.loads(json_data, strict=False)
2、 JSON. Dumps (data) converts Chinese characters to unicode encoding
Reason: JSON performs character conversion by default
Solution: add ensure_ASCII parameters
json.dumps(data, ensure_ascii=False)
Similar Posts:
- Python: json:json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19)
- [Solved] JSON check syntax error: json.decoder.JSONDecodeError: Invalid control character at: line 1 column
- [Solved] TypeError: string indices must be integers, not str
- [Solved] Python Error: UnicodeDecodeError: ‘gb2312’ codec can’t decode byte 0xa4 in position… : illegal multibyte sequence
- [Solved] json.decoder.JSONDecodeError: Expecting ‘,‘ delimiter: line xx column xx (char xxx)
- Python: How to Solve raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder…
- TypeError: Object of type ‘datetime‘ is not JSON serializable [Solved]
- SyntaxError: Non-ASCII character ‘\xe2‘ in file
- TypeError: the JSON object must be str, not ‘bytes’