【发布时间】:2023-03-29 01:00:02
【问题描述】:
我有一本字典,我正试图删除一个特定的对象。
{
"authorizationQualifier": "00",
"testIndicator": " ",
"functionalGroups": [
{
"functionalIdentifierCode": "SC",
"applicationSenderCode": "6088385400",
"applicationReceiverCode": "3147392555",
"transactions": [
{
"name": null,
"transactionSetIdentifierCode": "832",
"transactionSetControlNumber": "000000001",
"implementationConventionReference": null,
"segments": [
{
"BCT": {
"BCT01": "PS",
"BCT03": "2",
"id": "BCT"
}
}
]
}
]
}
]
}
我正在尝试删除对象的“段”列表,同时保留功能组和事务列表。
我试过了,
ediconverted = open("converted.json", "w")
with open('832.json','r') as jsonfile:
json_content = json.load(jsonfile)
for element in json_content:
element.pop('segments', None)
with open('converted.json', 'w') as data_file:
json_content = json.dump(json_content, data_file)
【问题讨论】:
-
请发布您尝试过的方式。
-
那不是字典;这是一个 JSON 块。
-
我使用loads() 将json 文件反序列化为字典。然后我可以通过使用 - shortdata = data["functionalGroups"][0]["transactions"][0] (数据是反序列化的 json 文件)来获取每个列表键;但是我不清楚如何删除段列表。我试过 .pop 没有运气
标签: python json dictionary