我能做什么:
我想要实现的目标:
如果我的请求只是一个子单元和失败响应,我该如何解析 数据方面我没有模型服务器返回
如何修改我的代码
示例:
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)));
}
}
});
}