Hello Team,
I have to use jsonobject in my groovy script.
but compilation is failing
http.request(GET) {
requestContentType = contentType.JSON
response.success = { resp, JSON ->
responseObj = JSON
String body = resp.entity.content.text
JSONObject jsonObject = new JSONObject(body)
log.warn(jsonObject.get("results").length())
if (jsonObject.get("results").length() <= 0){
return false
}
else{
return true
}
}
response.failure = { resp ->
responseObj= [error: "Request failed with status ${resp.status}"]
return false
}
}
could you please suggest any workaround for above problem?
Hi @Pavan
Where are you running the script?
You could try adding the import for org.json.JSONObject
I usually use the JsonSlurper class to parse JSON
import groovy.json.JsonSlurper
String jsonString = <some body string>
JsonSlurper slurper = new JsonSlurper()
Map myJson = slurper.parseText(jsonString)
String val = myJson.issue
String val2 = myJson.get("issue")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.