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")
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.