GSON,AndroidAnnotations-应为BEGIN_对象,但为字符串

GSON,AndroidAnnotations-应为BEGIN_对象,但为字符串,gson,android-annotations,Gson,Android Annotations,我搜索了类似的主题,但没有一个对我有帮助 我的回答是: { "success": "true", "data": { "id": "x", "user_name": "xxx", "email": "xxx@xxx.com", "first_name": "xxx", "last_name": "xx", "position": "xxx", "session_id": "xxx" } } 我的Java类是: 答复: public cla

我搜索了类似的主题,但没有一个对我有帮助

我的回答是:

{
"success": "true",
"data": {
    "id": "x",
    "user_name": "xxx",
    "email": "xxx@xxx.com",
    "first_name": "xxx",
    "last_name": "xx",
    "position": "xxx",
    "session_id": "xxx"
}
}

我的Java类是:

答复:

public class Response {

public String success;
public Data data;

public Response() {
}
public Response(String success, Data data) {

    this.success = success;
    this.data = data;
}
}

资料

}

我正在使用android注释建立rest连接。 我的客户是:

@Rest(rootUrl = "http://xxx/services", converters = {GsonHttpMessageConverter.class})

public interface MyRestClient {

    @Post("/login.php")
    ResponseEntity<Response> login(User user);

    RestTemplate getRestTemplate();

    void setRestTemplate(RestTemplate restTemplate);
}
我试图将“success”字段类型更改为boolean,boolean I Java类,但没有帮助。
我尝试将rest接口中的方法返回类型更改为void,然后没有错误,因此我认为错误与错误的响应类有关,但我不知道是什么错误。您能帮助我吗?

因为您的类与您提供的JSON相匹配,如果您能发布服务器真正发送给您的内容,我们将为您提供帮助。要进行调试,可以尝试传递对象而不是响应。Gson将放置一个映射或数组。服务器发送给我的完全相同,我使用Chrome上的Postman进行了检查。是否有可能从Java代码中以纯文本形式看到服务器响应?(可能使用不同的转换器或其他东西?)
@Rest(rootUrl = "http://xxx/services", converters = {GsonHttpMessageConverter.class})

public interface MyRestClient {

    @Post("/login.php")
    ResponseEntity<Response> login(User user);

    RestTemplate getRestTemplate();

    void setRestTemplate(RestTemplate restTemplate);
}
ResponseEntity<Response> resp = restCli.login(new User("xxx","xxx"));
Expected BEGIN_OBJECT but was String at line 1 column 4