Python Json formatiing



这是我的json输出。如何从下面的json中只提取name和Status。这几天我都被这件事伤透了脑筋。

我需要使用for循环才能得到这个?

{
"recipes": {
"47635": {
"name": "Desitnation Search",
"status": "SUCCESSFUL",
"kitchen": "eu",
"active": "YES",
"created_at": 1501672231,
"interval": 5,
"use_legacy_notifications": false
},
"65568": {
"name": "Validation",
"status": "SUCCESSFUL",
"kitchen": "us-west",
"active": "YES",
"created_at": 1522583593,
"interval": 5,
"use_legacy_notifications": false
},
"47437": {
"name": "Gateday",
"status": "SUCCESSFUL",
"kitchen": "us-west",
"active": "YES",
"created_at": 1501411588,
"interval": 10,
"use_legacy_notifications": false
}
},
"counts": {
"total": 3,
"limited": 3,
"filtered": 3
}
}

在这里使用for循环。

extracted_recipes = []
for recipe in d['recipes']:
extracted_recipes.append(recipe['name'],recipe['status'])

这将为您提供一个元组列表。

print(extracted_recipes)
[('Desitnation Search',"SUCCESSFUL"),("Validation","SUCCESSFUL"),("Gateday","SUCCESSFUL")]

最新更新