0
我想使用JavaScript動態創建以下格式的JSON。我試圖做到這一點,但它是如此嵌套,我一直在得到錯誤。你能幫我解決這個問題嗎?使用JavaScript動態創建JSON
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
{"name": "CommunityStructure", "size": 3812},
{"name": "HierarchicalCluster", "size": 6714},
{"name": "MergeEdge", "size": 743}
]
},
{
"name": "graph",
"children": [
{"name": "BetweennessCentrality", "size": 3534},
{"name": "LinkDistance", "size": 5731},
{"name": "MaxFlowMinCut", "size": 7840},
{"name": "ShortestPaths", "size": 5914},
{"name": "SpanningTree", "size": 3416}
]
},
{
"name": "optimization",
"children": [
{"name": "AspectRatioBanker", "size": 7074}
]
}
]
}
]}
它是同一結構的一部分,它本身一遍又一遍地重複。請幫我解決一下這個。
你試過'JSON.parse'嗎? – AdityaParab
你在找這樣的事嗎? http://stackoverflow.com/a/7220510/667599 – Throoze
不,我正在嘗試創建一個上述格式的新兒子。 –