发布时间:2022-08-09 文章分类:编程知识 投稿人:李佳 字号: 默认 | | 超大 打印

8
down vote

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 stringdef jsonObj =newJsonSlurper().parseText('{ "name":"Peter", "age": 23}')assert jsonObj.name =="Peter"assert jsonObj.age ==23//this won't work, because it's not definedassert jsonObj.gender ==null