我想创建一个这样的 JSON{ "beacons": { "0c:f3:ee:16:6f:15": { "label": "label", "major": "7", "minor": 15349, "uuid": "699EBC80-E1F3-11E3-9A0F-0CF3EE3BC012" }, "0c:f3:ee:16:6f:24": { "label": "label", "major": "7", "minor": 15364, "uuid": "699EBC80-E1F3-11E3-9A0F-0CF3EE3BC012" }, "0c:f3:ee:16:6f:53": { "label": "label", "major": "7", "minor": 15411, "uuid": "699EBC80-E1F3-11E3-9A0F-0CF3EE3BC012" } }}我已经创建了这样的信标对象beacon = { advertiser_mac: { 'major': major, 'minor': minor, 'uuid': proximity_uuid }}但我不知道如何像上面的例子一样将它们全部连接到一个对象中
1 回答
胡子哥哥
TA贡献1825条经验 获得超6个赞
beacon是字典。因此,如果您知道如何为 each 生成字典advertiser_mac,则可以进行键分配:
beacon = {}
advertiser_mac = "0c:f3:ee:16:6f:53"
advertiser_mac_dict = {
"label": "label",
"major": "7",
"minor": 15411,
"uuid": "699EBC80-E1F3-11E3-9A0F-0CF3EE3BC012"
}
beacon[advertiser_mac] = advertiser_mac_dict
beacon
{"0c:f3:ee:16:6f:53": {
"label": "label",
"major": "7",
"minor": 15411,
"uuid": "699EBC80-E1F3-11E3-9A0F-0CF3EE3BC012"
}
}
添加回答
举报
0/150
提交
取消