应为json,如下所示
我有一个位置列表和立方体列表
{
"Company": "my company",
"Locations": {
"India": {
"cubicals": [
"A-8954","B-3212"
]
},
"USA": {
"cubicals": [
"A-8954","B-3212"
]
}
}
}
编写groovy代码如下,cubicalList和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"
]
}
}
}