小编NSc*_*ara的帖子

Groovy 收集嵌套元素和外部元素

使用 Groovy,要求是收集地图的嵌套元素值及其顶级元素值。

不确定是否需要递归方法。

示例 JSON

{
"items": [
      {
      "attribute": "Type",
      "options":       
      [
                  {
            "label": "Type1",
            "value": "1"
         },
                  {
            "label": "Type2",
            "value": "2"
         }

      ]
   },
      {
      "attribute": "Size",
      "options":       [
                  {
            "label": "SizeA",
            "value": "A"
         },
                  {
            "label": "SizeB",
            "value": "B"
         }
      ]
   }
]
}
Run Code Online (Sandbox Code Playgroud)

收集后的预期输出

[
{attribute=Type,label=Type1,value=1},
{attribute=Type,label=Type2,value=2},
{attribute=Size,label=SizeA,value=A},
{attribute=Size,label=SizeB,value=B}
]
Run Code Online (Sandbox Code Playgroud)

groovy json nested collect

2
推荐指数
1
解决办法
1243
查看次数

标签 统计

collect ×1

groovy ×1

json ×1

nested ×1