![](/img/trans.png)
[英]Getting results from nested json with variable dict keys in python
[英]Getting keys of nested json string in python
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}
在 json 字符串上方考虑,我想从这个 json 字符串中获取具有适当层次结构的所有键,例如
id,类型,名称,ppu,击球手,
然后在面糊中:面糊,浇头
连击:id,类型
在打顶:id,类型
我正在使用python,有什么办法可以达到目的吗?
如果这是一个字符串,请尝试:
import json
json.loads(your_variable)
如果这是一个 dict 将其解析为字符串并使用上面的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.