Retrofit只返回成功/失败响应......没有模型......如何进行改造请求

时间:2017-12-30 15:42:09

标签: android retrofit2

我能做什么

  • 制作改造网络请求并获得成功回复
  • 这里我正在解析模型

我想要实现的目标

  • 如果我的请求只是一个子单元和失败响应,我该如何解析 数据方面我没有模型服务器返回

  • 如何修改我的代码

示例:

 public void GetHash() {

        prepareBody();

        Call<CheckSumHash> posts = retrofit.create(Restapi.class).getCheckSum(prepareHeaders(),prepareBody());

        mAlert = new SweetAlert(activity);
        mAlert.startProgress();

        //Enque the call
        posts.enqueue(new Callback<CheckSumHash>() {
            @Override
            public void onResponse(Call<CheckSumHash> call, Response<CheckSumHash> response) {
                mAlert.stopProgress();
                CheckSumHash mFacetData = response.body();

                Gson gson = new GsonBuilder().create();
                String json = gson.toJson(mFacetData);// obj is your object
                Map<String,String> result = new Gson().fromJson(json, Map.class);


                EventBus.getDefault().post(new BusHashSumResponse(result));
            }

            @Override
            public void onFailure(Call<CheckSumHash> call, Throwable error) {
                mAlert.stopProgress();
                //Set the error to the textview
                if(error instanceof SocketTimeoutException){
                    EventBus.getDefault().post(new ConnectionTimeout(activity.getResources().getString(R.string.str_socket_timeout)));
                }else if(error instanceof IOException){
                    EventBus.getDefault().post(new NoConnectivity(activity.getResources().getString(R.string.str_no_connectivity)));
                }
            }

        });
    }

0 个答案:

没有答案