这是我的JSON对象
{
"master": {
"node": "xyz",
"files": [{"type": "modified", "file": "test.txt"}]
},
"testbranch2": {
"node": "abc",
"files": [{"type": "modified", "file": "test.txt"}]
},
"testbranch": {
"node": "xxx",
"files": [{"type": "modified", "file": "test.txt"}],
}
}
我只需要对象键名称,例如" master"," testbranch2"," testbranch。如何使用groovy仅获取对象键名称?
答案 0 :(得分:6)
您可以使用JsonSlurper
import groovy.json.JsonSlurper
def json = '{ "master": ...'
def test = new JsonSlurper().parseText(json)
//if json comes from file you can do: new JsonSlurper().parse(new File('YOUR_JSON_FILE'))
println test.keySet()