Я хочу получить доступ к значениям 'dl_dst' из всех наборов в этих данных json
Я могу получить данные dl_dst, но он хранит 3 раза каждой точки данных спина к спине. Какую ошибку я совершил?
{'1': [{'actions': ['OUTPUT:1'],
'byte_count': 238,
'cookie': 0,
'duration_nsec': 833000000,
'duration_sec': 138,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 104,
'match': {'dl_dst': '00:00:00:00:00:01',
'dl_src': '00:00:00:00:00:02',
'in_port': 2},
'packet_count': 3,
'priority': 1,
'table_id': 0},
{'actions': ['OUTPUT:2'],
'byte_count': 140,
'cookie': 0,
'duration_nsec': 828000000,
'duration_sec': 138,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 104,
'match': {'dl_dst': '00:00:00:00:00:02',
'dl_src': '00:00:00:00:00:01',
'in_port': 1},
'packet_count': 2,
'priority': 1,
'table_id': 0},
{'actions': ['OUTPUT:1'],
'byte_count': 238,
'cookie': 0,
'duration_nsec': 809000000,
'duration_sec': 138,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 104,
'match': {'dl_dst': '00:00:00:00:00:01',
'dl_src': '00:00:00:00:00:03',
'in_port': 2},
'packet_count': 3,
'priority': 1,
'table_id': 0},
{'actions': ['OUTPUT:2'],
'byte_count': 140,
'cookie': 0,
'duration_nsec': 807000000,
'duration_sec': 138,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 104,
'match': {'dl_dst': '00:00:00:00:00:03',
'dl_src': '00:00:00:00:00:01',
'in_port': 1},
'packet_count': 2,
'priority': 1,
'table_id': 0},
{'actions': ['OUTPUT:1'],
'byte_count': 238,
'cookie': 0,
'duration_nsec': 787000000,
'duration_sec': 138,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 104,
'match': {'dl_dst': '00:00:00:00:00:01',
'dl_src': '00:00:00:00:00:04',
'in_port': 2},
'packet_count': 3,
'priority': 1,
'table_id': 0},
{'actions': ['OUTPUT:2'],
'byte_count': 140,
'cookie': 0,
'duration_nsec': 786000000,
'duration_sec': 138,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 104,
'match': {'dl_dst': '00:00:00:00:00:04',
'dl_src': '00:00:00:00:00:01',
'in_port': 1},
'packet_count': 2,
'priority': 1,
'table_id': 0},
{'actions': ['OUTPUT:CONTROLLER'],
'byte_count': 1944,
'cookie': 0,
'duration_nsec': 582000000,
'duration_sec': 168,
'flags': 0,
'hard_timeout': 0,
'idle_timeout': 0,
'length': 80,
'match': {},
'packet_count': 27,
'priority': 0,
'table_id': 0}]}
Вот код Python, который я написал
import requests
import pprint
import json
url = 'https://api.myjson.com/bins/19yp59'
get_data = requests.get(url)
get_data_json = get_data.json()
data = get_data_json['1']
Dest_Mac = []
for k in data:
for i in k['match']:
Dest_Mac.append(k['match']['dl_dst'])
print(Dest_Mac)
Это результаты для этого кода
['00: 00: 00: 00: 00: 01', '00: 00: 00: 00: 00: 01 ', '00: 00: 00: 00: 00: 01', '00: 00 : 00: 00: 00: 02 ', '00: 00: 00: 00: 00: 02', '00: 00: 00: 00: 00: 02 ', '00: 00: 00: 00: 00: 01 ', '00: 00: 00: 00: 00: 01', '00: 00: 00: 00: 00: 01 ', '00: 00: 00: 00: 00: 03', '00: 00: 00 : 00: 00: 03 ', '00: 00: 00: 00: 00: 03', '00: 00: 00: 00: 00: 01 ', '00: 00: 00: 00: 00: 01', '00: 00: 00: 00: 00: 01 ', '00: 00: 00: 00: 00: 04', '00: 00: 00: 00: 00: 04 ', '00: 00: 00: 00 : 00: 04' ]
Обратите внимание, что каждая точка данных печатается 3 раза.