我是 JSONObject 的新手,我正在尝试将LinkedHashMap<String, List<Node>>转换为 json 文件。地图的结构是这样的:
"element_one", {Node1, Node2, etc...}
"element_two", {Node1, Node2, etc...}
每个节点都有两个属性:值和标签。
我想要的是这样的:
{
"element_one": [
{
"items": [
{
"value": "1",
"label": "Donald"
},
{
"value": "2",
"label": "Goofy"
}]
}],
"element_two": [
{
"items": [
{
"value": "1",
"label": "Peter"
},
{
"value": "2",
"label": "Wendy"
}]
}}
我正在使用 JSONObject,我在不同的线程中寻找解决方案,但没有任何帮助。我知道这是一个特殊的问题,但我需要用这个数据结构得到这个结果。
难点是在地图内循环节点元素而不覆盖已插入 JSONObject 中的元素。
谢谢。