【发布时间】:2022-12-18 15:30:57
【问题描述】:
我想将字典的两项放入相应键中的一个实体中,如果 idx=... 在键中相似,则所有具有匹配键的可比较数据都成为字典中的一项,键为 0、1、... 见下面的演示数据要看懂,我learned thispage 但是我做不到如果你知道怎么做,请帮助我
演示数据:
{
"system": {
"camera[idx=0]": {
"fps": {
"value": 24,
"xpath": "/system/camera[idx=0]/fps",
"index": 3,
"string": "fps",
"uniqueID": "f8f90bde-e530-4cc6-b350-3e923d6ab456",
"editable": True,
"parent": "system",
"subParents": ["system", "camera[idx=0]"],
},
},
"motion_detection[idx=0]": {
"threshold_type": {
"value": 0,
"xpath": "/system/camera[idx=1]/ip/motion_detection[idx=0]/threshold_type",
"index": 5,
"string": "threshold_type",
"uniqueID": "5532aebe-501d-4275-ac4d-d6c8baf34d45",
"editable": True,
"parent": "system",
"subParents": [
"system",
"camera[idx=1]",
"ip",
"motion_detection[idx=0]",
],
},
},
"camera[idx=1]": {
"vendor_name": {
"value": "Raspberry",
"xpath": "/system/camera[idx=1]/vendor_name",
"index": 3,
"string": "vendor_name",
"uniqueID": "6ea8386b-fd11-44c4-88e8-b35b8eff9f43",
"editable": True,
"parent": "system",
"subParents": ["system", "camera[idx=1]"],
}
},
"motion_detection[idx=1]": {
"threshold_min": {
"value": 0,
"xpath": "/system/camera[idx=1]/ip/motion_detection[idx=1]/threshold_min",
"index": 5,
"string": "threshold_min",
"uniqueID": "c8eab5a0-e00a-44e9-8320-09e4c8243505",
"editable": True,
"parent": "system",
"subParents": [
"system",
"camera[idx=1]",
"ip",
"motion_detection[idx=1]",
],
},
},
}
}
期待数据
{
"system": {
"0": {
"camera": {
"fps": {
"value": 24,
"xpath": "/system/camera[idx=0]/fps",
"index": 3,
"string": "fps",
"uniqueID": "f8f90bde-e530-4cc6-b350-3e923d6ab456",
"editable": True,
"parent": "system",
"subParents": ["system", "camera[idx=0]"],
},
},
"motion_detection": {
"threshold_type": {
"value": 0,
"xpath": "/system/camera[idx=1]/ip/motion_detection[idx=0]/threshold_type",
"index": 5,
"string": "threshold_type",
"uniqueID": "5532aebe-501d-4275-ac4d-d6c8baf34d45",
"editable": True,
"parent": "system",
"subParents": [
"system",
"camera[idx=1]",
"ip",
"motion_detection[idx=0]",
]
}
}
},
"1": {
"camera": {
"vendor_name": {
"value": "Raspberry",
"xpath": "/system/camera[idx=1]/vendor_name",
"index": 3,
"string": "vendor_name",
"uniqueID": "6ea8386b-fd11-44c4-88e8-b35b8eff9f43",
"editable": True,
"parent": "system",
"subParents": ["system", "camera[idx=1]"]
}
},
"motion_detection": {
"threshold_min": {
"value": 0,
"xpath": "/system/camera[idx=1]/ip/motion_detection[idx=1]/threshold_min",
"index": 5,
"string": "threshold_min",
"uniqueID": "c8eab5a0-e00a-44e9-8320-09e4c8243505",
"editable": True,
"parent": "system",
"subParents": [
"system",
"camera[idx=1]",
"ip",
"motion_detection[idx=1]",
]
}
}
}
}
}
【问题讨论】:
标签: python dictionary