为什么读json文件报这个错?
问题描述:
这个报错是怎么了?
with open('celoacc.json', 'r') as f:
jdict = json.load(f)
total = []
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)
答
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)
报错是json数据格式错误,不排除引号错误,如果是引号错误,使用下面方法即可解决,如果不是,你去看看celoacc文件第二行附近是不是有个格式错误了
with open('celoacc.json', 'r') as f:
txt=f.read()
txt=txt.replace("'",'"')
jdict = json.load(txt)
total = []
有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力