JSON to Groovy parser Stack Overflow

JSON to Groovy parser - Stack Overflow

If you are on Groovy 1.8 or later, there is a build in JsonSlurper you can use this way:

import groovy.json.JsonSlurper

//Attention: you have to use double quotes inside the json string
def jsonObj = new JsonSlurper().parseText( '{ "name":"Peter", "age": 23}' )

assert jsonObj.name == "Peter"
assert jsonObj.age == 23
//this won't work, because it's not defined
assert jsonObj.gender == null 
原文地址:https://www.cnblogs.com/lexus/p/2558111.html