onResponse没有被 Retrofit调用?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (247)

我能够在Retroefit中使用日志拦截器获得响应,但是我的onResponse没有被调用。

我使用的两个模型类如下所示

MainResponse.class

public class MainResponse {

@SerializedName("status")
@Expose
private String status;
@SerializedName("data")
@Expose
private Data data;

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

public Data getData() {
    return data;
}

public void setData(Data data) {
    this.data = data;
}
}

Data.class

public class Data {

@SerializedName("messages")
@Expose
private List<Object> messages = null;
@SerializedName("result")
@Expose
private Result result;

public List<Object> getMessages() {
    return messages;
}

public void setMessages(List<Object> messages) {
    this.messages = messages;
}

public Result getResult() {
    return result;
}

public void setResult(Result result) {
    this.result = result;
 }
}

回调代码如下所示:

  Call<MainResponse> call = imsClient.fetchStatus(userCredentials);
    call.enqueue(new Callback<MainResponse>() {
        @Override
        public void onResponse(Call<MainResponse> call, Response<MainResponse> response) {
            Log.e("Ei", "In response");
            MainResponse mainResponse = response.body();
            Data data = mainResponse.getData();
            Result result = data.getResult();
            Toast.makeText(PrimaryLogin.this, "Welcome" + result.getFirstName() + result.getLastName(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(Call<MainResponse> call, Throwable t) {


        }
    });

失败时会调用回调,但如果成功执行调用,则不会发生任何情况。

日志:

{"status":"success","data":{"messages":[],"result":{"clinicCode":"Medics","firstName":"Charles","lastName":"Sanders","officeId":0,"id":7834,"startDate":1508142509926,"timeZoneId":0,"userDetailId":6,"userName":"charles","jobTitle":{"id":1,"text":"Doctor","count":1},"isSuperUser":false,"clientId":10,"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGluaWNDb2RlIjoiTWVkaWNzIiwiZW1haWwiOm51bGwsImVuZERhdGUiOm51bGwsImZpcnN0TmFtZSI6IkNoYXJsZXMiLCJsYXN0TmFtZSI6IlNhbmRlcnMiLCJvZmZpY2VJZCI6MCwiaWQiOjc4MzQsInNwZWNpYWx0eUlkIjpudWxsLCJzdGFydERhdGUiOjAsInRpbWVab25lSWQiOjAsInVzZXJEZXRhaWxJZCI6NiwidXNlck5hbWUiOiJjaGFybGVzIiwib2ZmaWNlIjpudWxsLCJzcGVjaWFsdHkiOm51bGwsInRpbWVab25lIjpudWxsLCJ1c2VyRGV0YWlsIjpudWxsLCJwYXJhbWV0ZXJzIjpudWxsLCJqb2JUaXRsZSI6bnVsbCwiaXNTdXBlclVzZXIiOmZhbHNlLCJjbGllbnRJZCI6MTAsImNvZGUiOm51bGwsInRva2VuIjpudWxsLCJlbXBsb3llZUlkIjoxNCwicHJvdmlkZXJJZCI6bnVsbCwiaXNBY3RpdmUiOmZhbHNlLCJpc0xvY2tlZCI6ZmFsc2UsImxhc3RQYXNzd29yZENoYW5nZWQiOjAsImxvY2tlZENvZGVJZCI6bnVsbCwibG9ja2VkRGF0ZVRpbWUiOm51bGwsInBhc3N3b3JkIjpudWxsLCJwYXRpZW50SWQiOm51bGwsInByZWZMYW5nSWQiOm51bGwsInNlc3Npb25JZCI6NzgzNCwiY3JlYXRlZEJ5IjpudWxsLCJlbXBsb3llZSI6bnVsbCwibGFzdE1vZGlmaWVkQnkiOm51bGwsImxvY2tlZENvZGUiOm51bGwsInBhdGllbnQiOm51bGwsInByZWZMYW5nIjpudWxsLCJhcHBsaWNhdGlvbk5hbWUiOm51bGwsIm1hY2hpbmVJZCI6bnVsbCwibGFuZ0lkIjpudWxsLCJjb3VudHJ5Q29kZSI6IlVTIn0.B-C9YWEHWQJue83TnGUa3dnmQYz0ngdNPUqH_6AG8tU","employeeId":14,"isActive":false,"isLocked":false,"lastPasswordChanged":0,"sessionId":0}}}
提问于
用户回答回答于

在结果模型中,你将数据存储为Integer,响应时间很长,因此会调用错误。

所属标签

可能回答问题的人

  • uncle_light

    5 粉丝518 提问8 回答
  • 嗨喽你好

    7 粉丝480 提问8 回答
  • 人生的旅途

    10 粉丝484 提问7 回答
  • 无聊至极

    4 粉丝504 提问6 回答

扫码关注云+社区

领取腾讯云代金券