jenkins pipeline readJSON-如何访问嵌套元素
我无法使用readJSON访问嵌套JSON oldJson字符串:jenkins pipeline readJSON-如何访问嵌套元素,jenkins,groovy,jenkins-pipeline,jenkins-plugins,jenkins-groovy,Jenkins,Groovy,Jenkins Pipeline,Jenkins Plugins,Jenkins Groovy,我无法使用readJSON访问嵌套JSON oldJson字符串: {"branch":{"type-0.2":{"version":"0.2","rc":"1","rel":"1","extras":"1"}}} 我尝试访问它,如示例所示 但它失败了。我认为这是因为“rc”嵌套在“type-02”中。如何访问它?您总是可以通过使用括号符号或点符号的嵌套键来获取嵌套元素的值 stage('Read-JSON') { steps { script {
{"branch":{"type-0.2":{"version":"0.2","rc":"1","rel":"1","extras":"1"}}}
我尝试访问它,如示例所示
但它失败了。我认为这是因为“rc”嵌套在“type-02”中。如何访问它?您总是可以通过使用括号符号或点符号的嵌套键来获取嵌套元素的值
stage('Read-JSON') {
steps {
script {
def oldJson = '{"branch":{"type-0.2":{"version":"0.2","rc":"1","rel":"1","extras":"1"}}}'
def props = readJSON text: oldJson
println(props['branch']['type-0.2']['rc'])
\\ or println(props.'branch'.'type-0.2'.'rc')
}
}
}
输出:
[Pipeline] stage
[Pipeline] { (Read-JSON)
[Pipeline] script
[Pipeline] {
[Pipeline] readJSON
[Pipeline] echo
1
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Read-JSON)
[Pipeline] script
[Pipeline] {
[Pipeline] readJSON
[Pipeline] echo
1
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage