我试图访问某个json从api调用返回到地图中的元素,因此我可以将它传递给另一个api调用。我似乎无法正确创建一个变量,并给它我需要的值。这里是返回的json,我需要访问Id元素。访问常规图中的JSON元素
{
"totalSize": 1,
"done": true,
"records": [
{
"attributes": {
"type": "User",
"url": "/services/data/v24.0/sobjects/User/MYIDNUMBER"
},
"Id": "MYIDNUMBER"
}
]
}
这里的RESTful服务呼叫我使用,我试图访问id元素并把它放在SFID,所以我可以在我的下一个API调用中使用它
def http = new HTTPBuilder(instance_domain)
http.request(GET,JSON) { req ->
uri.path = "services/data/v24.0/query/"
uri.query = [q:"SELECT Id from User WHERE Email = '[email protected]'"]
headers['Authorization'] = "Bearer $access_token"
response.success = { resp, json ->
json.each{ key,value ->
sfMap = [sfUser: [json: json]]
}
sfId = sfMap[records.Id]
}
response.failure = { resp, json ->
println resp.status
println json.errorCode
println json.message
}
}
我得到以下错误这部分portletized版本的服务器
2014-07-08 08:02:39,710 ERROR [http-bio-443-exec-161] portal-web.docroot.html.portal.render_portlet_jsp:154 groovy.lang.MissingPropertyException: No such property: records for class: groovyx.net.http.HTTPBuilder$RequestConfigDelegate
不应该是'json.records.Id'? – Will
这就是我会想到的。试了很早就得到了'2014-07-08 08:24:54,735错误[http-bio-443-exec-170] portal-web.docroot.html.portal.render_portlet_jsp:154 java.lang.NullPointerException' – Baci