无法正确解析json?

时间:2019-07-09 01:55:27

标签: json recursion

我一直试图像下面的示例中那样解析json,但是我还没有做到这一点。

我已经将json解析为一个json对象并做了一个递归函数,但是我还没有得到正确的结果

def dirlisting(tree, path, heap):
  for (k, v) in tree.items():
    k = 'a_' if k == 'a' else k
    if type(v) is dict:
      path.append(k)
      heap = dirlisting(v, path, heap)[2]
      path.pop(-1)
    elif type(v) is int:
      path.append(k)
      heap.append(path)
      path = [""]
  return (tree, path, heap)

似乎不起作用

{
  "c":{
    "libs":{
      "file":0,
      "gif":{
        "gif.worker.js":0,
        "gif.txt":0
      }
    }
  },
  "d":0,
  "e":{
    "one":{
      "doc":0,
      "sample":0
    }
  }
}
Into

[["c","libs","file"],
 ["c","libs","gif","gif.worker.js"],
 ["c","libs","gif","gif.txt"],
 ["d"],
 ["e","one","doc"],
 ["e","one","sample"]]

0 个答案:

没有答案