【发布时间】:2021-07-14 06:46:43
【问题描述】:
[
{
"builtin_name": "custom_template",
"fields": [
{
"id": 10012,
"field_type": "OBJECT_SET",
"tooltip_text": "",
"name_plural": "",
"name_singular": "reference",
"backref_name": "reference",
"backref_tooltip_text": "",
"allow_multiple": false,
"allowed_otypes": [
"schema",
"table",
"attribute",
"user",
"groupprofile",
"groupprofile"
],
"options": null,
"builtin_name": null
},
{
"id": 8,
"field_type": "OBJECT_SET",
"tooltip_text": null,
"name_plural": "Stewards",
"name_singular": "Steward",
"backref_name": "Steward",
"backref_tooltip_text": null,
"allow_multiple": true,
"allowed_otypes": ["user", "groupprofile", "groupprofile"],
"options": null,
"builtin_name": "steward"
}
],
"id": 16,
"title": "Custom template"
},
{
"builtin_name": "new_template",
"fields": [
{
"id": 10011,
"field_type": "PICKER",
"tooltip_text": "",
"name_plural": "",
"name_singular": "status",
"backref_name": "",
"backref_tooltip_text": "",
"allow_multiple": false,
"allowed_otypes": null,
"options": [
{
"old_index": 0,
"article_id": null,
"tooltip_text": null,
"in_use": true,
"title": "Done"
}
],
"builtin_name": null
}
],
"id": 1899,
"title": "New Template"
}
]
使用这个 JSON 对象,我想替换 fields 列表,其中 id=16 and title=Custom template。我已经生成了要用于替换的对象。
这是我尝试过的,但没有奏效:
i=0
jdata_copy = jdata #this is so I can compare
for t in jdata:
if(t["title"]=="Custom template" and t["id"]==16):
jdata_copy[i]["fields"] = repl_data
i+=1
我四处寻找一个简单的 json 替换,但没有找到。
感谢一些帮助。
谢谢!
【问题讨论】:
标签: json python-3.x replace