假设我有一个文件.json包含以下内容:[
{
"name": "Shirt1",
"product_id": "001234"
},
{
"name": "Shirt2",
"product_id": "005678"
}
]
使用Python3,我想在两个字典中添加以下行:
^{pr2}$
这是我的代码:import json
import os
with open("file.json", "r", encoding="utf8") as in_file:
INP = json.load(in_file)
DATA = []
for item in INP:
item["type"] = "external"
item["reviews_allowed"] = "false"
DATA.append(item)
with open("file2.json", "w", encoding="utf-8") as out_file:
out_file.write(json.dumps(DATA, indent=2, ensure_ascii=False))
os.rename("file2.json", "file.json")
但是,我得到了以下结论:[
{
"name": "Shirt1",
"product_id": "001234",
"type": "external",
"reviews_allowed": "false"
},
{
"name": "Shirt2",
"product_id": "005678",
"type": "external",
"reviews_allowed": "false"
}
]
有没有办法去掉双引号?
非常感谢您抽出宝贵的时间!在