【发布时间】:2017-11-17 07:39:23
【问题描述】:
我正在尝试遍历 IP 地址列表,并从我的 url 中提取 JSON 数据,并尝试将 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 是的,你有,对此感到抱歉。谢谢!
标签: json python-2.7 list nested