我是 python 新手,我有一个 json 响应(见下文)。我想搜索 id 的值site1
并列出 id 的所有值。
{ "listSiteResponse" : { "count":4 ,"site" : [ {
"id": "28e4cc3f-d0c2-46f4-9e0c-b532fd148292",
"simpleid": 15,
"name": "Site1",
"description": "Blr1",
"location": "Bangalore1",
}, {
"id": "188d4b47-1955-43e1-82a8-7ccedcfc636b",
"simpleid": 16,
"name": "Site2",
"description": "Blr2",
"location": "Bangalore2",
}, {
"id": "63fab512-4b52-4038-8a3b-4632f1911dca",
"simpleid": 17,
"name": "Site3",
"description": "Blr3",
"location": "Bangalore3",
}, {
"id": "2db3949a-ba2f-4e93-85b5-24a995fa3d99",
"simpleid": 18,
"name": "Site4",
"description": "Blr4",
"location": "Bangalore4",
}
}}
我尝试了以下脚本来列出 ID,但出现错误:
from pprint import pprint
json_data=open('logs/CurrentSitesList.txt')
data = json.load(json_data)
test=data["listSiteResponse"]["site"]["id"]