我有一个这样的字典:
{ "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" }] } ] }
Run Code Online (Sandbox Code Playgroud)
基本上是具有任意深度的嵌套列表,字典和字符串的字典.
遍历此方法以提取每个"id"键的值的最佳方法是什么?我想实现相当于XPath查询,如"// id"."id"的值始终是一个字符串.
所以从我的例子来看,我需要的输出基本上是:
["abcde", "qwerty", "xyz", "fghi", "asdf", "yuiop"]
Run Code Online (Sandbox Code Playgroud)
订单并不重要.