我對json很新,我怎樣才能讓一個JSON對象的結構(輸出字符串)會是這樣?我正在使用org.json庫。這是一個json數組contians json數組嗎?如何製作JSON對象,輸出結果如下?
我輸入這樣的:
111(root)
----222(child of 111)
--------333(child of 222)
--------444(child of 222)
----123(child of 111)
--------456(child of 123)
--------456(child of 123)
我怎樣才能讓一個JSON輸出會是什麼樣子的打擊,
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{
"name": "AgglomerativeCluster",
"value": 3938
},
{
"name": "CommunityStructure",
"value": 3812
}
]
},
{
"name": "graph",
"children": [
{
"name": "BetweennessCentrality",
"value": 3534
},
{
"name": "LinkDistance",
"value": 5731
}
]
}
]
},
{
"name": "animate",
"children": [
{
"name": "Easing",
"value": 17010
},
{
"name": "FunctionSequence",
"value": 5842
}
]
}
]
}
感謝您的幫助!
非常感謝,但插入後如何檢索價值?我需要檢查一個孩子是否已經存在。像treemap。我嘗試過flare.getJSONObject(「children」),這會導致我錯誤「JSONObject [」children「]不是JSONObject。」 –
非常感謝!我找到了一種方法來檢索JSONObject的值tempObject = tempJSONArray.getJSONObject(i)tempObject.get(「name」)。equals(name); –