此问题与以下内容相似:d3.nest() key and values conversion to name and children
但是,我的数据(来自JSON文件)具有以下格式:
{
"Key1": [
"child1",
"child2",
{
"key1Sub1": [
"child1",
"child2",
{
"key1sub1sub": [
"child1",
"child2"
]
},
{
"key1sub2": [
"child1",
"child2"
]
},
{
"key1sub3": [
"child1",
"child2"
]
}
]
}
]
}
我将如何使用地图功能来格式化此类对象,或者如何编辑树图源以获取如下格式:
{
"name": "Top Level",
"children": [
{
"name": "Level 2: A",
"children": [
{ "name": "Son of A" },
{ "name": "Daughter of A" }
]
},
{ "name": "Level 2: B" }
]
}