0
我有一個文件路徑列表作爲txt文件,需要轉換成json格式。 例如,將路徑轉換爲python中的json格式
/src/test/org/apache/hadoop/ipc/TestRPC.java
/src/test/org/apache/hadoop/ipc/TestRPC2.java
我想:
for item in input:
hierarchy = item.split('/')
hierarchy = hierarchy[1:]
local_result = result
children=[]
for node in hierarchy:
print node
if node in local_result:
local_result[node]
local_result[node] = children
print result
但它有不同的結果不是我想要的。
在這種情況下,我想使下面的json文件。
{
"name": "src",
"children": {
"name": "test",
"children": {
"name": "org",
.....
.....
....
}
}
}
您可能要結帳http://stackoverflow.com/questions/8484943/construct-a-tree-from-list-os-file-paths-python-performance-dependent,雖然最終結果不是JSON,但樹和嵌套的JSON對象沒有那麼不同。也許你可以重用邏輯。 – reticentroot