我对 RESTful api 感到困惑。 代码:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.JSON
import org.codehaus.groovy.grails.web.json.JSONObject
def isMailer = new HTTPBuilder( 'http://mailer-api.com' )
isMailer.request( GET, JSON ) {
uri.path = '/is/mail/rest/json/' + token
isMailer.auth.basic 'ddd', 'aaa'
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp, json ->
// response handler for a success response code:
System.out << json
if(json.has("DISP_NAME")) {
println "************************"
res = "Yes"
} else if (json.has("ListError")) {
res = "No"
}
}
}
// handler for any failure status code:
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}
}
return res
}
输出 wrt System.out << json
{
"DISP_NAME" : "owner-atob",
"DOM_NAME" : "mailer",
"GROUP_ID" : "1229815",
"GROUP_NAME" : "owner-atob"
}
错误 wrt if(json.has("DISP_NAME"))
No signature of method: org.apache.http.conn.EofSensorInputStream
is applicable for argument types: (java.lang.String) values: [DISP_NAME]
我的问题:
我只想检查DISP_NAME
json 输出中是否存在密钥(在此处)。因此,我想在 if-else 块中区分我的工作。