解析JSON时出现Python错误
所以我试图从这个JSON中找到IP地址:解析JSON时出现Python错误,python,json,python-requests,Python,Json,Python Requests,所以我试图从这个JSON中找到IP地址: [{"id":"001788fffe48cbdb","internalipaddress":"192.168.1.102"}] 所以我的代码是: r_lights = requests.get('https://www.meethue.com/api/nupnp') js= r_lights.json() hue
[{"id":"001788fffe48cbdb","internalipaddress":"192.168.1.102"}]
所以我的代码是:
r_lights = requests.get('https://www.meethue.com/api/nupnp')
js= r_lights.json()
hue_lights = [js[index]["name"] for index in js]
但是,它返回错误:
TypeError: list indices must be integers or slices, not dict
我已经使用该代码成功地搜索了代码中的其他JSON,但我不确定如何将其更改为在此处工作。尝试:
hue_lights = [index["name"] for index in js]
或者如果你想要ip的
hue_lights = [index["internalipaddress"] for index in js]
直接使用字典的字符串值:
for obj in index['name']:
hue_lights = obj['one']['two']