我想將我的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