在groovy中将映射列表转换为嵌套映射
我有一份地图清单在groovy中将映射列表转换为嵌套映射,groovy,hashmap,Groovy,Hashmap,我有一份地图清单 b = [{key1=hello, key2=world}, {key1=hello2, key2=world2}, {key1=hello3, key2=world3}, {key1=hello4, key2=world4}] 我怎么把它转换成这样的东西 b = [{key1=hello, key2=world, {key1=hello2, key2=world2, {key1=hello3, key2=world3, {key1=hello4, key2=world4}}
b = [{key1=hello, key2=world}, {key1=hello2, key2=world2}, {key1=hello3, key2=world3}, {key1=hello4, key2=world4}]
我怎么把它转换成这样的东西
b = [{key1=hello, key2=world, {key1=hello2, key2=world2, {key1=hello3, key2=world3, {key1=hello4, key2=world4}}}}]
输出:
{
"key1": "hello",
"key2": "world",
"next": {
"key1": "hello2",
"key2": "world2",
"next": {
"key1": "hello3",
"key2": "world3",
"next": null
}
}
}
你已经试过代码了吗?第二个b不是地图对不起,我是groovy新手。我还没有尝试任何东西。AddInjecteer说,b不是一个有效的映射,它介于映射和列表之间。。。你到底想要什么样的输出?
{
"key1": "hello",
"key2": "world",
"next": {
"key1": "hello2",
"key2": "world2",
"next": {
"key1": "hello3",
"key2": "world3",
"next": null
}
}
}