需要您的帮助才能找到解决方案。我有以下json
[{ “源”: “AA”, “目标”: “BB”, “指标”: “10”, “local_interface”: “100”, “remote_interface”: “200”}, { “源”: “AA”, “目标”: “BB”, “指标”: “10”, “local_interface”: “111”, “remote_interface”: “222”}, { “源”: “BB”, “目标”: “AA”, “指标”: “10”, “local_interface”: “200”, “remote_interface”: “100”}]
目标是:
希望这是有道理的。
答案 0 :(得分:0)
你是在追求像这样简单的事情吗?
j = [{"source":"AA","target":"BB","metric":"10",
"local_interface":"100","remote_interface":"200"},
{"source":"AA","target":"BB","metric":"10",
"local_interface":"111","remote_interface":"222"},
{"source":"BB","target":"AA","metric":"10",
"local_interface":"200","remote_interface":"100"}]
s = j[0]["source"]
print(s)
t = j[0]["target"]
print(t)
li = j[0]["local_interface"]
print(li)
print('Find source ==', t)
for i in range(1,3):
if j[i]['source'] == t:
print("Is match:", j[i])
print()
del(j[1])
print("after deletion:", j)