Forum Discussion
Guyz,
I guess this is pretty old but I found a easier way using jsonSlurper-
JSON Response-
{
"IDs": [
1,
27
],
"Items": {
"1": {
"ItemName": "Item1",
"ItemType": "Type1",
"ItemVersion": 5,
"ItemUrlLocation": "a/b/c/1.zip"
},
"27": {
"ItemName": "Item2",
"ItemType": "Type2",
"ItemVersion": 5.3,
"ItemUrlLocation": "a/b/c/d/e/1.zip"
}
},
"status": {
"responseStatus": "Success",
"responseCode": 200
}
}
##### Groovy Script ########
import com.eviware.soapui.support.XmlHolder
import net.sf.*
import net.sf.json.*
import net.sf.json.groovy.*
def ResponseMessage = testRunner.testCase.testSteps["Req_Name"].testRequest.response.contentAsString
def ItemID, ItemName, ItemType, ItemVersion, i =0
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
log.info "${jsonSlurper.status.responseCode} ${jsonSlurper.status.responseStatus}"
while(jsonSlurper.ItemIDs!=null){
ItemID = jsonSlurper.ItemIDs
ItemName = jsonSlurper.ItemIDs.toString()]ItemName
ItemType = jsonSlurper.ItemIDs.toString()]ItemType
ItemVersion = jsonSlurper.ItemIDs.toString()]ItemVersion
log.info "$ItemID::$ItemName::$ItemType::$ItemCriticality::$ItemVersion"
i++
}
I guess this is pretty old but I found a easier way using jsonSlurper-
JSON Response-
{
"IDs": [
1,
27
],
"Items": {
"1": {
"ItemName": "Item1",
"ItemType": "Type1",
"ItemVersion": 5,
"ItemUrlLocation": "a/b/c/1.zip"
},
"27": {
"ItemName": "Item2",
"ItemType": "Type2",
"ItemVersion": 5.3,
"ItemUrlLocation": "a/b/c/d/e/1.zip"
}
},
"status": {
"responseStatus": "Success",
"responseCode": 200
}
}
##### Groovy Script ########
import com.eviware.soapui.support.XmlHolder
import net.sf.*
import net.sf.json.*
import net.sf.json.groovy.*
def ResponseMessage = testRunner.testCase.testSteps["Req_Name"].testRequest.response.contentAsString
def ItemID, ItemName, ItemType, ItemVersion, i =0
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
log.info "${jsonSlurper.status.responseCode} ${jsonSlurper.status.responseStatus}"
while(jsonSlurper.ItemIDs!=null){
ItemID = jsonSlurper.ItemIDs
ItemName = jsonSlurper.ItemIDs.toString()]ItemName
ItemType = jsonSlurper.ItemIDs.toString()]ItemType
ItemVersion = jsonSlurper.ItemIDs.toString()]ItemVersion
log.info "$ItemID::$ItemName::$ItemType::$ItemCriticality::$ItemVersion"
i++
}
Related Content
Recent Discussions
- 2 days ago