Bootstrap

Python读取JSON文件的小错误

  • json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 59)

  这是因为JSON文件太大而读取错误,解决方法是按字符串的形式一行一行的读取。

file = open("test.json", 'r', encoding='utf-8')
content = []
for line in file.readlines():
    dict = json.loads(line)
    content.append(dict)
  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

   这是因为JSON文件中使用的是单引号,改为双引号即可。

;