我想使用JSONSlurper解析此数据并将其转换为地图,然后使用变量将数据传递给模板。
{
"biodata": {
"Ruby": {
"Expertise": "web development",
"EXperience": "5 years"
},
"Dylon": {
"Expertise": "Java",
"EXperience": "2 years"
}
}
}

这样的事情:
def myJson = fetchedJson
def experienceDylon = myJson.biodata.dylon.experience

如何使用groovy实现这一目标?
答案 0 :(得分:2)
考虑这个例子:
import groovy.json.*
def file = new File("importData.json")
def myJson = new JsonSlurper().parse(file)
// note original JSON has 'EXperience'
def result = myJson['biodata']['Dylon']['EXperience']
assert '2 years' == result