我有一个 C# 字典对象,其中包含该文件可用的文件名和文件夹。我想将数据转换为分层树。下面是数据。如何将其转换为树结构 JSON。
我查看了这个示例,但无法获得所需的输出。
+-----------------------------------------------+|
| Name | Path
|------------------------------------------------|
| Kitchen supplies | Shopping / Housewares |
| Groceries | Shopping / Housewares |
| Cleaning supplies | Shopping / Housewares |
| Office supplies | Shopping / Housewares |
| Retile kitchen | Shopping / Remodeling |
| Ceiling | Shopping / Paint bedroom |
| Walls | Shopping / Paint bedroom |
| Misc | null |
| Other | Shopping |
+-----------------------------------------------+|
应该生成如下输出:
{"text":".","children": [
{
Name:' Shopping',
children:[{
Name:'Housewares',
children:[{
Name:'Kitchen supplies',
leaf:true,
},{
Name:'Groceries',
leaf:true,
},{
Name:'Cleaning supplies',
leaf:true,
},{
Name: 'Office supplies',
leaf: true,
}]
}, {
Name:'Remodeling',
children:[{
Name:'Retile kitchen',
leaf:true,
},{
Name:'Paint bedroom',
children: [{
Name: 'Ceiling',
leaf: true
}, {
Name: 'Walls',
iconCls: 'Name',
}]
},
{
Name: 'Other',
leaf: true
}]
}]
},
{
Name: 'Misc',
leaf: true
}
]}