我想将我的json响应值添加到数组中。我的Groovy脚本,Groovy:为什么节点返回null
import groovy.json.*
def ResponseMessage = '''{
"Unit": {
"Screen": [{
"Profile ": {
"ID ": 12,
"Rate ": 0
},
"Rate ": 600,
"Primary ": 1,
"Audio ": [{
"Id ": 1,
"Name ": null
}],
"Pre ": 5,
"Post ": 1
}]
}
} '''
def json = new JsonSlurper().parseText(ResponseMessage)
def Screen = json.Unit.Screen
log.info Screen
def array= []
Screen.each { s ->
array.addAll(s.Rate,s.Primary,s.Pre)
log.info "array : " + array
}
阵列正在恢复, 信息:数组:[NULL,NULL,NULL]
你在你的Json空间?即:'“Profile”'< - 在末尾 –
是:(手动删除空格后,我得到了这个错误错误:java.lang.IndexOutOfBoundsException:Index:600,Size:0 – Gkm