在执行GET调用后,我得到了一个json响应,我需要从该json响应中获取一个特定的值。
{
"identifier": "id",
"items": [
{
"channelGroupId": 26,
"controlMethod": "MANUAL",
"portChannelId": 0,
"ethernetFecMode": "NONE",
"ethernetLoopback": "NONE",
"isSwitchablePort": false,
"negotiationMode": "UNKNOWN",
"configuredDuplexMode": "AUTO_NEGOTIATE",
"isConnectorPresent": "FALSE",
"mtu": 1514,
"delay": 0,
"isPromiscuous": false,
"isSpanMonitored": false,
"ifSpeed": {
"longAmount": 0
},
"isFloatingPep": false,
"isInMaintenance": false,
"adminStatus": "UP",
"operStatus": "DOWN",
"type": "PROPVIRTUAL",
"name": "Bundle-Ether26",
"id": 27423442, #I want to get this value if the channelGroupId = 26
"uuid": "5cc095bb-e67d-4827-8a46-c3d2bf9d450f",
"displayName": "f03d09bc[4427434_10.104.120.141,Bundle-Ether26]"
},
{
"channelGroupId": 36,
"controlMethod": "MANUAL",
"portChannelId": 0,
"ethernetFecMode": "NONE",
"ethernetLoopback": "NONE",
"isSwitchablePort": false,
"negotiationMode": "UNKNOWN",
"configuredDuplexMode": "AUTO_NEGOTIATE",
"isConnectorPresent": "FALSE",
"mtu": 1514,
"delay": 0,
"isPromiscuous": false,
"isSpanMonitored": false,
"ifSpeed": {
"longAmount": 0
},
"isFloatingPep": false,
"isInMaintenance": false,
"adminStatus": "UP",
"operStatus": "DOWN",
"type": "PROPVIRTUAL",
"name": "Bundle-Ether36",
"id": 27423438,
"uuid": "fff16259-4079-4d67-bdf9-c1a4720f01c3",
"displayName": "f03d09bc[4427434_10.104.120.141,Bundle-Ether36]"
},
{
"channelGroupId": 21,
"controlMethod": "MANUAL",
"portChannelId": 0,
"ethernetFecMode": "NONE",
"ethernetLoopback": "NONE",
"isSwitchablePort": false,
"negotiationMode": "UNKNOWN",
"configuredDuplexMode": "AUTO_NEGOTIATE",
"isConnectorPresent": "FALSE",
"mtu": 1514,
"delay": 0,
"isPromiscuous": false,
"isSpanMonitored": false,
"ifSpeed": {
"longAmount": 0
},
"isFloatingPep": false,
"isInMaintenance": false,
"adminStatus": "UP",
"operStatus": "DOWN",
"type": "PROPVIRTUAL",
"name": "Bundle-Ether21",
"id": 27423440,
"uuid": "40c11ffd-34cd-4e80-be1d-58899dba4894",
"displayName": "f03d09bc[4427434_10.104.120.141,Bundle-Ether21]"
}
],
"status": {
"statusCode": 0,
"statusMessage": "Get operation is successful",
"hideDialog": true
}
}
我想提取id
的值(即27423440
),在同一个字典中,channelGroupId
的值为26
。
我尝试了以下代码,但无法访问字典
if response.status_code == 200:
if "success" in response.text:
#print(response.text)
full_response = response.json()
list_of_pagp = full_response['items']
print(list_of_pagp)
for i in list_of_pagp:
if(list_of_pagp['channelGroupId'] == 26 ):
instanceId = list_of_pagp[id]
break
print(instanceId)
不知道我错过了什么。
1条答案
按热度按时间tcomlyy61#
似乎只是个低级的错误,
从以下位置修复:
收件人: