为什么读json文件报这个错?

为什么读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中有单引号问题,可以参考下面文章:
https://blog.csdn.net/qq_41375609/article/details/100118545


觉得有用的话采纳一下哈

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 = []

有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力