回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个arista开关的嵌套字典输出,并希望迭代这个json列表/dict,为每个接口提取以下信息。你知道吗</p>
<p><code>Interfacename(like Ethernet29/1)</code>和<code>actorPortPriority(32768)</code></p>
<p>如何访问这些数据?你知道吗</p>
<p>我试着做:</p>
<pre><code>for k, v in data.items():
print(v['interfaces'])
print(v['interfaces']['actorPortPriority']
</code></pre>
<p>但我没有明白。
据我所知,我有一个嵌套的dict,但实际上我没有得到它
遍历嵌套的<code>dict</code>s</p>
<p><code>data</code>样本:</p>
<pre><code>{'interfaces': {'Ethernet29/1': {'actorOperKey': '0x00c8',
'actorPortId': 117,
'actorPortPriority': 32768,
'actorPortState': {'activity': True,
'aggregation': True,
'collecting': True,
'defaulted': False,
'distributing': True,
'expired': False,
'synchronization': True,
'timeout': False},
'actorPortStatus': 'bundled',
'partnerOperKey': '0x82af',
'partnerPortId': 16643,
'partnerPortPriority': 32768,
'partnerPortState': {'activity': True,
'aggregation': True,
'collecting': True,
'defaulted': False,
'distributing': True,
'expired': False,
'synchronization': True,
'timeout': False},
'partnerSysId': '7F9B,00-23-04-ee-be-cc'},
'Ethernet30/1': {'actorOperKey': '0x00c8',
'actorPortId': 121,
'actorPortPriority': 32768,
'actorPortState': {'activity': True,
'aggregation': True,
'collecting': True,
'defaulted': False,
'distributing': True,
'expired': False,
'synchronization': True,
'timeout': False},
'actorPortStatus': 'bundled',
'partnerOperKey': '0x82af',
'partnerPortId': 259,
'partnerPortPriority': 32768,
'partnerPortState': {'activity': True,
'aggregation': True,
'collecting': True,
'defaulted': False,
'distributing': True,
'expired': False,
'synchronization': True,
'timeout': False},
'partnerSysId': '7F9B,00-23-04-ee-be-cc'}},
'markers': {'markers': ['*']}}
{'interfaces': {'Ethernet16/1': {'actorOperKey': '0x0385',
'actorPortId': 65,
'actorPortPriority': 32768,
'actorPortState': {'activity': True,
'aggregation': True,
'collecting': True,
'defaulted': False,
'distributing': True,
'expired': False,
'synchronization': True,
'timeout': False},
'actorPortStatus': 'bundled',
'partnerOperKey': '0x0001',
'partnerPortId': 49,
'partnerPortPriority': 32768,
'partnerPortState': {'activity': True,
'aggregation': True,
'collecting': True,
'defaulted': False,
'distributing': True,
'expired': False,
'synchronization': True,
'timeout': False},
'partnerSysId': '8000,28-99-3a-fa-50-fc'}},
'markers': {'markers': ['*']}}
{'interfaces': {'Ethernet11/1': {'actorOperKey': '0x0067',
'actorPortId': 45,
'actorPortPriority': 0,
'actorPortState': {'activity': False,
'aggregation': True,
'collecting': False,
'defaulted': True,
'distributing': False,
'expired': False,
'synchronization': False,
'timeout': False},
'actorPortStatus': 'noAgg',
'partnerOperKey': '0x0000',
'partnerPortId': 0,
'partnerPortPriority': 0,
'partnerPortState': {'activity': False,
'aggregation': False,
'collecting': False,
'defaulted': False,
'distributing': False,
'expired': False,
'synchronization': False,
'timeout': True},
'partnerSysId': '0000,00-00-00-00-00-00'},
'Ethernet11/2': {'actorOperKey': '0x0067',
'actorPortId': 46,
'actorPortPriority': 32768,
'actorPortState': {'activity': False,
'aggregation': True,
'collecting': False,
'defaulted': True,
'distributing': False,
'expired': False,
'synchronization': False,
'timeout': False},
'actorPortStatus': 'noAgg',
'partnerOperKey': '0x0000',
'partnerPortId': 0,
'partnerPortPriority': 0,
'partnerPortState': {'activity': False,
'aggregation': False,
'collecting': False,
'defaulted': False,
'distributing': False,
'expired': False,
'synchronization': False,
'timeout': True},
'partnerSysId': '0000,00-00-00-00-00-00'}},
'markers': {'markers': ['*']}}
</code></pre>