小编Amy*_*Amy的帖子

如何检查json中的密钥,我从RESTful api获取输出

我对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: …
Run Code Online (Sandbox Code Playgroud)

groovy json httpbuilder

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

groovy ×1

httpbuilder ×1

json ×1