Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析JSON时出现Python错误_Python_Json_Python Requests - Fatal编程技术网

解析JSON时出现Python错误

解析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

所以我试图从这个JSON中找到IP地址:

[{"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']