开发者

example to build groovy json and with groovy builder needed

empData1.groovy
def empMap[] =
       [1:2,
           2:2,
       3:[1:2,3:3,4:890,A:B],  //Map inside Map
       4:4,
       6:7
      ]


empData2.groovy
def empMap1[] =
       [91:21,
           92:22,
       93:[81:82,83:3,84:890,A:B], ////Map inside Map
       94:4,
       96:7
      ]

emp3.groovy -

- Q1: how can i build a builder for like empMap/empMap1 - Q2: if i want to do in emp3.grrovy like empData1.include(empMap1) map data copies to map2

is the same thing is achievavle vis groovy json how ?

is this possible to do

def json = new JsonBuilder()
 def result = json {
      1  2              //build a map with 1 as key 2 value without sinlge quaote is this possible
      3  33             //build a map with 3 as key 33 value without sinlge quaote is this possible
 }

println result

**Answer
def json = new JsonBuilder()
 def result = json {
      '1'    '2'              
      '3'    '33'开发者_JAVA百科             
 }

println  result

My output [1:2, 3:33]

but i try to build something like this

def json = new JsonBuilder()
 def result = json {
      '1'    '2'              
      '3'    '33'             
      '4'   (
          '1'   '3'
          '4'   '5'
      )
 }

println  result

it gives me compilation error any clue to resolve it


Anish, I suggest you try this instead to make it compile:

import groovy.json.JsonBuilder

def json = new JsonBuilder()
def result = json {
  '1'    '2'              
  '3'    '33'             
  '4'   {
      '1'   '3'
      '4'   '5'
  }
}
println  json
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜