【发布时间】:2018-04-17 10:27:36
【问题描述】:
这是我的代码中的实际响应和预期响应完全不同。谁能找出我的错误,提前谢谢。
主要活动
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.movies_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
Call<List<UserModel>> call = apiService.getUserInfo();
call.enqueue(new Callback<List<UserModel>>() {
@Override
public void onResponse(Call<List<UserModel>> call, Response<List<UserModel>> response) {
int statusCode = response.code();
List<UserModel> rs = response.body();
Log.i("xxxxxxggggxxxxxxxxxxx",rs+"");
}
@Override
public void onFailure(Call<List<UserModel>> call, Throwable t) {
}
});
usermodel
public class UserModel {
@SerializedName("profile")
@Expose
private Profile profile;
public Profile getProfile() {
return profile;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
}
profile
public class Profile {
@SerializedName("isActive")
@Expose
private Boolean isActive;
@SerializedName("name")
@Expose
private Name name;
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}
}
名字
public class Name {
@SerializedName("first")
@Expose
private String first;
@SerializedName("last")
@Expose
private String last;
public String getFirst() {
return first;
}
public void setFirst(String first) {
this.first = first;
}
public String getLast() {
return last;
}
public void setLast(String last) {
this.last = last;
}
}
ApiCLIENT
public interface ApiInterface {
@POST("test")
Call<List<UserModel>> getUserInfo();
}
它的实际响应是
[{"profile":{"id":"d712923e-62a1-11e5-9d70-feff819cdc9f","email":"trevor@ribot.co.uk","avatar":"https://s3-eu-west-1.amazonaws.com/api.ribot.io/trevor_big.png","dateOfBirth":"1990-01-01T00:00:00.000Z","hexColor":"#B60042","bio":"Trevor crafts elegant multi-device experiences with pixels and magic while tanked up on artisan coffee and Col-Erase pencil shaving fumes. He can also be found going on about Disneyland (again), playing video games terribly, or drawing a face on something.","isActive":true,"name":{"first":"Trevor","last":"May"}}}]
这是我收到的回复info.androidhive.retrofit.model.UserModel@9c6c34c
这是我的代码中的实际响应和预期响应完全不同。谁能找出我的错误,提前谢谢。
【问题讨论】:
-
您的预期响应是什么?
-
[{"profile":{"id":"d712923e-62a1-11e5-9d70-feff819cdc9f","email":"trevor@ribot.co.uk","avatar":" s3-eu-west-1.amazonaws.com/api.ribot.io/… 用像素和魔法打造优雅的多设备体验,同时喝着手工咖啡和 Col-Erase 铅笔剃须烟雾。他还可以在迪斯尼乐园(再次)、玩电子游戏或在上面画脸某事。","isActive":true,"name":{"first":"Trevor","last":"May"}}}]
标签: java android json retrofit2