您好,我想知道如何從矩陣中的 json 資料中獲取資料?為了更好地解釋:
{
"00": "Echo reply",
"03":{ "00" : "Destination Unreachable - Net Unreachable",
"01" : "Destination Unreachable - Host Unreachable",
"02" : "Destination Unreachable - Protocol Unreachable",
"03" : "Destination Unreachable - Port Unreachable",
"04" : "Destination Unreachable - Fragmentation Needed & DF Set",
"05" : "Destination Unreachable - Source Route Failed",
"06" : "Destination Unreachable - Destination Network Unknown",
"07" : "Destination Unreachable - Destination Host unknown",
"08" : "Destination Unreachable - Source Host Isolated",
"09" : "Destination Unreachable - Network Administratively Prohibited",
"0a" : "Destination Unreachable - Host Administratively Prohibited",
"0b" : "Destination Unreachable - Network unreachable for TOS",
"0c" : "Destination Unreachable - Host unreachable for TOS",
"0d" : "Destination Unreachable - Communication Administratively Prohibited"
},
"04": "Source Quench",
"05": {
"00": "Redirect - Datagram for the Network",
"01": "Redirect - Datagram for the Host",
"02": "Redirect - Datagram for the TOS & Network",
"03": "Redirect - Datagram for the TOS & Host"
},
"08": "Echo",
"09": "Router Advertisement",
"0a": "Router Selection",
"0b": {
"01":"Time Exceeded - Time to live exceeded in Transit",
"02":"Time Exceeded - Fragment Reassembly Time Exceeded"
},
"0c": {
"00": "Parameter Problem - Pointer indicates the error",
"01": "Parameter Problem - Missing a Required Option",
"02": "Parameter Problem - Bad Length"
},
"0d": "Timestamp",
"0e": "Timestamp Reply",
"0f": "Information Request",
"10": "Information Reply",
"11": "Address Mask Request",
"12": "Address Mask Reply",
"1e": "Traceroute"
}
這是我的 json 檔案,我想從“03”->“00”中獲取,但是,我不知道如何到達那里
f = open('icmp.json', )
data = json.load(f)
print(data[type, code]) #i was also trying data[type[code]] or data[type][code]
但不為我作業?:D 請幫忙
uj5u.com熱心網友回復:
加載json時,它是python中的字典。你可以像這樣得到你的物品:
f = open('icmp.json', )
data = json.load(f)
print(data['03']['00'])
uj5u.com熱心網友回復:
將我的 json 檔案更改為此有效 :) Thx all for your response
{
"00": {"00": "Echo reply" },
"03":{ "00" : "Destination Unreachable - Net Unreachable",
"01" : "Destination Unreachable - Host Unreachable",
"02" : "Destination Unreachable - Protocol Unreachable",
"03" : "Destination Unreachable - Port Unreachable",
"04" : "Destination Unreachable - Fragmentation Needed & DF Set",
"05" : "Destination Unreachable - Source Route Failed",
"06" : "Destination Unreachable - Destination Network Unknown",
"07" : "Destination Unreachable - Destination Host unknown",
"08" : "Destination Unreachable - Source Host Isolated",
"09" : "Destination Unreachable - Network Administratively Prohibited",
"0a" : "Destination Unreachable - Host Administratively Prohibited",
"0b" : "Destination Unreachable - Network unreachable for TOS",
"0c" : "Destination Unreachable - Host unreachable for TOS",
"0d" : "Destination Unreachable - Communication Administratively Prohibited"
},
"04": {"00": "Source Quench"},
"05": {
"00": "Redirect - Datagram for the Network",
"01": "Redirect - Datagram for the Host",
"02": "Redirect - Datagram for the TOS & Network",
"03": "Redirect - Datagram for the TOS & Host"
},
"08":{"00": "Echo " },
"09":{"00": "Router Advertisement"},
"0a": {"00": "Router Selection" },
"0b": {
"01":"Time Exceeded - Time to live exceeded in Transit",
"02":"Time Exceeded - Fragment Reassembly Time Exceeded"
},
"0c": {
"00": "Parameter Problem - Pointer indicates the error",
"01": "Parameter Problem - Missing a Required Option",
"02": "Parameter Problem - Bad Length"
},
"0d": {"00": "Timestamp" },
"0e": {"00": "Timestamp Reply" },
"0f": {"00": "Information Request"},
"10": {"00": "Information Reply"},
"11": {"00": "Address Mask Request"},
"12": {"00": "Address Mask Reply"},
"1e": {"00": "Traceroute"}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/325029.html
