浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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 
posted on 2012-06-21 18:08  lexus  阅读(277)  评论(0编辑  收藏  举报