Python 如何仅使用子键访问嵌套字典的值?
我有以下嵌套字典:Python 如何仅使用子键访问嵌套字典的值?,python,string,dictionary,itertools,Python,String,Dictionary,Itertools,我有以下嵌套字典: { "category": "string", "top_bottom": { "count": 0, "data": [ { "store_name": "string", "store_id": "string", "value": 0 } ], "end_name": "string" } } 我想得到键存储\u name的值。我怎样才能做到这一点呢?你
{
"category": "string",
"top_bottom": {
"count": 0,
"data": [
{
"store_name": "string",
"store_id": "string",
"value": 0
}
],
"end_name": "string"
}
}
我想得到键
存储\u name
的值。我怎样才能做到这一点呢?你需要知道到达那里的“完整路径”。例如,如果你的字典名为myDict
,你就可以用
myDict["top_bottom"]["data"][0]["store_name"]
如果您无法了解“完整路径”,那么最好考虑为数据采用不同的结构