我想通过这个搜索“name”并返回名称,我已经有了它的代码。但是,我需要同时返回“1”或“4”,以便最终得到:
1-角灯
然后,我可以将HTTP PUT与程序的其余部分一起发送到正确的设备。我找不到任何关于如何处理这件事的信息,非常感谢您的帮助
names = [js[index]["name"] for index in js]
print (names)
{
"1": {
"state": {
"on": true,
"bri": 114,
"alert": "none",
"reachable": true
},
"type": "Dimmable light",
"name": "corner light",
},
"4": {
"state": {
"on": true,
"bri": 180,
"alert": "none",
"reachable": true
},
"type": "Dimmable light",
"name": "Back light",
},
"5": {
"state": {
"on": true,
"bri": 228,
"alert": "none",
"reachable": true
},
"type": "Dimmable light",
"name": "Best Bulb",
},
"7": {
"state": {
"on": false,
"bri": 254,
"alert": "none",
"reachable": false
},
"type": "Dimmable light",
"name": "our bulb",
},
只需在语句中连接索引和分隔符:
这就产生了输出
顺便说一句,您需要将布尔值大写(True&;错误)以保持Python的快乐
相关问题 更多 >
编程相关推荐