我想遍歷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