yuraku
9 years agoContributor
Can't get values from JSON array. [null object]
Hi. I'm trying to parse response as an array of arrays.
For some reason "An error occurred [null object]"
[ { "id": , "number": , "name": "some info", "description": "<p><\/p><p><br><\/p><p><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t<\/span>Lorenzo<\/p>", "description_no_html": "sdgsgs", "state": "New", "priority": "Low", }, { ... } ]
My script is:
def category = "bla bla bla" def ResponseMessage = testRunner.testCase.testSteps["Get all incidents from Samanage before termination"].testRequest.response.contentAsString def jsonSlurper = new JsonSlurper().parseText(ResponseMessage) def responseSize = jsonSlurper.size() def terminations = [] def responseCategory //Get all the terminations for specified date from response for (int i=0;i<responseSize;i++){ responseCategory = jsonSlurper[i].category.name.toString() if (responseCategory.equals(category)) terminations << jsonSlurper[i].id }
Can someone help me with that? The JSON is valid and in case if
jsonSlurper[1].id
i'll get correct value. But in FOR structure it's not working
fixed by adding try/catch block (tests now passed)
but still some strange behavior ( the script is working but exception occurred)