groovy jsonBuilder用于json键数组

oyxsuwqo  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(132)

json应该如下
我有一张地点和目标的清单

{
    "Company": "my company",
    "Locations": {
        "India": {
            "cubicals": [
                "A-8954","B-3212"
            ]
        },
        "USA": {
            "cubicals": [
                "A-8954","B-3212"
            ]
        }
    }
}

字符串
编写的groovy代码如下,其中,nationalList和nationsList如所述

cubicalList=["A-8954","B-3212"]
nationsList=["India", "USA"]
def json = new groovy.json.JsonBuilder()
name="my company"
json {
    company name
    Locations {
            "${nationsList}" (
            {
                cubicals cubicalsList
            }
            )
    }
}

println json.toPrettyString()


在这里,印度和美国走到一起,任何关于这方面的投入都将是非常有用的。

{
    "company": "my company",
    "Locations": {
        "[India, USA]": {
            "cubicals": [
                "A-8954",
                "B-3212"
            ]
        }
    }
}

disbfnqx

disbfnqx1#

你是说像

json {
    company name
    Locations {
        nationsList.each { nation ->
            "${nation}" {
                cubicals cubicalsList
            }
        }
    }
}

字符串

相关问题