我有一本这样的字典:
{
"id": "abcde",
"key1": "blah",
"key2": "blah blah",
"nestedlist": [
{
"id": "qwerty",
"nestednestedlist": [
{
"id": "xyz",
"keyA": "blah blah blah"
},
{
"id": "fghi",
"keyZ": "blah blah blah"
}
],
"anothernestednestedlist": [
{
"id": "asdf",
"keyQ": "blah blah"
},
{
"id": "yuiop",
"keyW": "blah"
}
]
}
]
}
基本上是一个具有嵌套列表、字典和字符串的字典,具有任意深度。
遍历这个过程以提取每个“ id”键的值的最佳方法是什么?我想实现类似于“//id”的 XPath 查询。“ id”的值总是一个字符串。
So from my example, the output I need is basically:
["abcde", "qwerty", "xyz", "fghi", "asdf", "yuiop"]
秩序不重要。