Найти - Пользователи
Полная версия: Библиотека json
Начало » Python для новичков » Библиотека json
1
oksromn
Как из json записать нужный мне ключ в переменную?
Например, мне нужно записать айпишники в переменные.
Мне нужно перейти по ключу ‘scan’, а дальше что делать не знаю…

 {'scan': {'192.168.1.40': {'addresses': {'ipv4': '192.168.1.40'}, 'status': {'state': 'up', 'reason': 'localhost-response'}, 'hostnames': [{'name': '', 'type': ''}], 'vendor': {}}
py.user.next
  
>>> data = {'scan': {'192.168.1.40': {'addresses': {'ipv4': '192.168.1.40'}, 'status': {'state': 'up', 'reason': 'localhost-response'}, 'hostnames': [{'name': '', 'type': ''}], 'vendor': {}}}}
>>> 
>>> scan = data['scan']
>>> addresses = scan[list(scan)[0]]['addresses']
>>> addresses['ipv4']
'192.168.1.40'
>>> 
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB