Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Restlet使用JSON web服务?_Java_Json_Rest_Restlet_Restlet 2.0 - Fatal编程技术网

Java 如何使用Restlet使用JSON web服务?

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

我正在尝试使用Restlet使用restful web服务。服务给了我JSON,所以我使用一个JsonRepresentation对象来获取它,但它不起作用。调用
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()的内容。我猜身份验证是错误的或类似的。