天天看点

【Python】JSON读取大量数据错误:JSONDecodeError: Extra data: line 2 column 1

【Python】JSON读取大量数据错误:JSONDecodeError: Extra data: line 2 column 1

大量数据,里面有多行多列,出现类似标题报错

raise JSONDecodeError(“Extra data”, s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 104)
           

可以逐行读取,然后再处理成列表

import json
file = open("papers.json", 'r', encoding='utf-8')
papers = []
for line in file.readlines():
    dic = json.loads(line)
    papers.append(dic)
 
 
print(len(papers))	输出结果正常了
4337
Process finished with exit code 0	
           

so easy!