我有以下格式的 JSON 檔案:
[
{"url": "example1.com", "date": "Jan 1", "text": ["Here is some ", "example 1 text"]},
{"url": "example2.com", "date": "Jan 2", "text": ["Here is some ", "example 2 text"]},
]
我使用以下方法上傳到 Python 中:
with open("data.json") as data:
data = json.load(data)
我想重新格式化上傳的資料,以便合并文本而不用括號括起來,例如:
[
{"url": "example1.com", "date": "Jan 1", "text": "Here is some example 1 text"},
{"url": "example2.com", "date": "Jan 2", "text": "Here is some example 2 text"},
]
uj5u.com熱心網友回復:
您可以按如下方式格式化“文本”欄位:
with open("data.json") as data:
data = json.load(data)
for website in data:
website["text"] = ' '.join(website["text"])
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/487362.html
