我想遍历IP地址列表,并从我的URL中提取JSON数据,并试图将该JSON数据放入嵌套列表中。Python:将JSON对象追加到嵌套列表
看起来好像我的代码一遍又一遍覆盖我的列表,并且只显示一个JSON对象,而不是我指定的多个对象。
这里是我的代码:
for x in range(0, 10):
try:
url = 'http://' + ip_addr[x][0] + ':8080/system/ids/'
response = urlopen(url)
json_obj = json.load(response)
except:
continue
camera_details = [[i['name'], i['serial']] for i in json_obj['cameras']]
for x in camera_details:
#This only prints one object, and not 10.
print x
如何将我的JSON对象追加到一个列表,然后提取“名”和“串联”值到嵌套表?
请正确缩进代码...我修正了它吗? –
@WillemVanOnsem是的,对此抱歉。谢谢! – juiceb0xk