【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!