我正在尝试获取此数据并打印为文本字符串,我遇到的效果最糟!使它工作的问题。这是我正在与之合作以更好地了解我正在开发环境控制器并且我的sonoff开关结合使用的源 https://github.com/FirstCypress/LiV/blob/master/software/liv/iotConnectors/sonoff/sonoff .py 一旦完成,此代码可用于两页,因此请忽略温度键等 m = json.loads(content)
co2 = m["Value"]我需要“ TaskValues”下的“ Value”的值在几乎任何情况下都应该为1或0,我将如何以正确的形式提取该键?"Sensors":[{"TaskValues": [{"ValueNumber":1,"Name":"Switch","NrDecimals":0,"Value":0}],"DataAcquisition": [{"Controller":1,"IDX":0,"Enabled":"false"},{"Controller":2,"IDX":0,"Enabled":"false"},{"Controller":3,"IDX":0,"Enabled":"false"}],"TaskInterval":0,"Type":"Switch input - Switch","TaskName":"relias","TaskEnabled":"true","TaskNumber":1}],"TTL":60000}
2 回答
牛魔王的故事
TA贡献1830条经验 获得超3个赞
"Value"如前所述,嵌套在您的json中。要获得所需的内容,您需要遍历父数据结构:
m = json.loads(content)
# This is a list
a = m.get('Sensors')
# This is a dictionary
sensor = a[0]
# This is a list
taskvalue = sensor.get('TaskValues')
# Your answer
value = taskvalue[0].get('Value')
添加回答
举报
0/150
提交
取消