[英]Error reading big json file due to json.load
我在讀取大 json 文件時遇到問題。 JSONDecodeError:額外數據:第 1 行第 884 列(字符 883)。
文件 test2.json 在這里: https://github.com/SilverYar/TransportDataMiner
該錯誤是由於這些行代碼行引起的:
import nltk
from nltk.stem.snowball import RussianStemmer
from nltk.corpus import stopwords
import nltk, string, json
with open('C:\\Creme\\token\\test2.json') as fin:
text = json.load(fin)
我不明白如何解決它。 幫我修一下。
您的 json 文件的內容似乎無效,有多個對象但沒有用“,”分隔。
例如,一個有效的 json object 應該是:
[{"title":"some text", "subtitle": "some text"},
{"title":"some text", "subtitle": "some text"},
{"title":"some text", "subtitle": "some text"}]
讀取它的一個簡單技巧是讀取文件並將字符串格式化為正確的 json 格式:
with open('test2.json', 'r') as fin:
text = fin.read()
formated_text = text.replace('}{', '},{')
json_data = json.loads(f'[{formated_text}]')
print(len(json_data))
# 11772
好吧,我了解 unveriatlifdoafoh GH (PO opg )))_FI++ SE(G&B 在某種意義上的變化,解決舊的(架構、e2e 測試、開發工具等)和新的(可訪問性、Typescript 集成、人工智能聊天機器人采用等) .) 問題是從整個 JS 會議的不同應用方法中獲得見解。 strong text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.