Java 如何使用Restlet使用JSON web服务?
我正在尝试使用Restlet使用restful web服务。服务给了我JSON,所以我使用一个JsonRepresentation对象来获取它,但它不起作用。调用Java 如何使用Restlet使用JSON web服务?,java,json,rest,restlet,restlet-2.0,Java,Json,Rest,Restlet,Restlet 2.0,我正在尝试使用Restlet使用restful web服务。服务给了我JSON,所以我使用一个JsonRepresentation对象来获取它,但它不起作用。调用jsonRepresentation.getJsonObject()时,我得到一个空指针异常 这是我的密码: ClientResource resource = new ClientResource("https://api.prosper.com/api/Listings?$top=3"); resource.setChal
jsonRepresentation.getJsonObject()
时,我得到一个空指针异常
这是我的密码:
ClientResource resource =
new ClientResource("https://api.prosper.com/api/Listings?$top=3");
resource.setChallengeResponse(
ChallengeScheme.HTTP_BASIC,
"username",
"password");
try {
JsonRepresentation jsonRepresentation =
new JsonRepresentation(resource.getResponse().getEntity());
jsonRepresentation.getJsonObject();
} catch (Exception e) { }
你知道问题是什么吗?或者我如何解决这个问题?我想你错过了服务电话:
ClientResource resource = (...)
(...)
Representation repr = resource.get();
JsonRepresentation jsonRepresentation = new JsonRepresentation(repr);
JSONObject jsonObj = jsonRepresentation.getJsonObject();
希望对你有帮助。
Thierry调试resource.getResponse()的内容。我猜身份验证是错误的或类似的。