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