【发布时间】:2015-09-15 17:27:25
【问题描述】:
所以我有一个改造界面:
public interface RestUserInformation {
@GET("/api/me")
void getInfo(Callback<UserInformation> callback);
}
一个 RestAdapter:
RestAdapter userInformation = newRestAdapter.Builder()
.setEndpoint(IP_ADDRESS)
.setRequestInterceptor(requestInterceptor)
.build();
进行 API 调用并接收 JSON 正文答案,例如:
{"user":{
"id":50,
"email":"mail@mail.com",
"first_name":"chris",
"last_name":"cr",
"birthdate":"1817-03-04",
"gender":1,
"country":"fr"
{
"id":8,
"language":"Spanish",
"flag_path":"public/images/flags/Argentina.ico",
"created_at":"2014-11-05T20:42:39.294Z",
"updated_at":"2014-11-05T20:42:39.294Z",
"name":"Argentina","available":false,
"i18n_key":null
}
}
}
我想解析它并用它填充一个类,所以我创建了类 UserInformation.java:
public class UserInformation {
int id;
String email;
String first_name;
String last_name;
String birthdate;
int gender;
String country; }
我一直在尝试使用回调函数来做到这一点:
RestUserInformation getUserInfo = userInformation.create(RestUserInformation.class);
getUserInfo.getInfo(new Callback<UserInformation>() {
@Override
public void success(UserInformation user, Response response) {
}
@Override
public void failure(RetrofitError error) {
}
});
我已经尝试了很多东西,但它不起作用,并且 UserInformation 类的属性保持为空.. 关于如何做的任何想法?
【问题讨论】:
-
什么 POJO 映射到 JSON 的根目录?
标签: java android json retrofit