Python json.loads 加载包含单引号文本报错 json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes
文本文件内容为:{'info1': '塑料格', 'info2': '不分', 'info3': '不分', 'brand1': "EVA'S FRUIT"}
加载:
with open(txtFile, "r",errors='ignore',encoding='utf8') as f: txt = f.read() return json.loads(txt)
报错
File "D:\Python39\lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) File "D:\Python39\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "D:\Python39\lib\json\decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 2 (char 3)
with open(txtFile, "r",errors='ignore',encoding='utf8') as f: # txt = str(f.read()).replace('\'','"').replace("\"S","\'") txt = str(f.read()).replace('\'', '"') aa=json.loads(txt) print(1) return json.loads(txt)