简体   繁体   English

Groovy map(带有项目的数组position)到对象的Z466DEEC76ECDF5FCA6D38571F6324D54

[英]Groovy map (with array position of item) to json list of objects

Input:输入:

import groovy.json.JsonBuilder
new JsonBuilder([test: 'test', test2: 'test2']).toPrettyString()

or或者

import groovy.json.JsonOutput
JsonOutput.prettyPrint(JsonOutput.toJson([test: 'test', test2: 'test2']))

Output: Output:

{
   "test" : "test",
   "test2" : "test2"
}

But how I will process the following in groovy language?但是我将如何用 groovy 语言处理以下内容?

Input:输入:

[test : 'test', testing[0].T1_Id : 'test1', testing[1].T2_Id : 'test2']

Output: Output:

{
   "test" : "test",
   "testing" : [
      {
         "T1_Id" : "test1"
      },
      {
         "T2_Id" : "test2"
      }
   ]
}
def data = [
   "test" : "test",
   "testing" : [
      [
         "T1_Id" : "test1"
      ],
      [
         "T2_Id" : "test2"
      ]
   ]
]
new JsonBuilder(data).toPrettyString()

should return you the desired json应该返回你想要的 json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM