From c5bf501d8b507d1e3e79541e7ac9b45910860b4d Mon Sep 17 00:00:00 2001 From: 陈奇 <1650699704@qq.com> Date: Wed, 29 May 2019 16:17:07 +0800 Subject: [PATCH] 添加新功能 --- app/src/main/java/com/moral/yunfushao/httputils/HttpUtils.java | 52 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 31 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/moral/yunfushao/httputils/HttpUtils.java b/app/src/main/java/com/moral/yunfushao/httputils/HttpUtils.java index 7614692..a3caa31 100644 --- a/app/src/main/java/com/moral/yunfushao/httputils/HttpUtils.java +++ b/app/src/main/java/com/moral/yunfushao/httputils/HttpUtils.java @@ -26,6 +26,7 @@ public class HttpUtils { /** * Get������ + * * @param url * @param params * @param cacheMode @@ -53,14 +54,14 @@ public void onSuccess(String s, Call call, Response response) { XLog.e("result:" + s); try { - JSONObject resJosn= new JSONObject(s); + JSONObject resJosn = new JSONObject(s); JSONObject jsonObject = resJosn.getJSONObject("data"); int errno = jsonObject.optInt("code"); String message = jsonObject.optString("msg"); - if(errno == 0){ - httpCallBack.onSuccess(jsonObject.optString("info"),message); - }else{ - httpCallBack.onFail(errno,message); + if (errno == 0) { + httpCallBack.onSuccess(jsonObject.optString("info"), message); + } else { + httpCallBack.onFail(errno, message); } } catch (JSONException e) { e.printStackTrace(); @@ -109,6 +110,7 @@ /** * Post������ + * * @param url * @param params * @param cacheMode @@ -136,16 +138,22 @@ public void onSuccess(String s, Call call, Response response) { XLog.e("result:" + s); try { - JSONObject resJosn= new JSONObject(s); - JSONObject jsonObject = resJosn.getJSONObject("data"); - int errno = jsonObject.optInt("code"); - String message = jsonObject.optString("msg"); - if(errno == 0){ - httpCallBack.onSuccess(jsonObject.optString("info"),message); - }else{ - httpCallBack.onFail(errno,message); + JSONObject resJosn = new JSONObject(s); + if (resJosn.has("data")) { + JSONObject jsonObject = resJosn.getJSONObject("data"); + int errno = jsonObject.optInt("code"); + String message = jsonObject.optString("msg"); + if (jsonObject.length() == 0 || errno == 0) { + httpCallBack.onSuccess(jsonObject.optString("info"), message); + } else { + httpCallBack.onFail(errno, message); + } + } else { + XLog.e("result jsonObject:"); } } catch (JSONException e) { + httpCallBack.onFail(503, e.getMessage()); + XLog.e("result jsonObject:" + e); e.printStackTrace(); } @@ -188,6 +196,7 @@ /** * ������������ + * * @param url * @param params * @param uploadCallBack @@ -211,13 +220,13 @@ public void onSuccess(String s, Call call, Response response) { XLog.e("result:" + s); try { - JSONObject resJosn= new JSONObject(s); + JSONObject resJosn = new JSONObject(s); JSONObject jsonObject = resJosn.getJSONObject("data"); int errno = jsonObject.optInt("code"); String message = jsonObject.optString("msg"); - if(errno == 0){ - uploadCallBack.onSuccess(jsonObject.optString("info"),message); - }else{ + if (errno == 0) { + uploadCallBack.onSuccess(jsonObject.optString("info"), message); + } else { uploadCallBack.onFail(message); } } catch (JSONException e) { @@ -268,6 +277,7 @@ /** * ������������ + * * @param url * @param params * @param uploadCallBack @@ -293,13 +303,13 @@ public void onSuccess(String s, Call call, Response response) { XLog.e("result:" + s); try { - JSONObject resJosn= new JSONObject(s); + JSONObject resJosn = new JSONObject(s); JSONObject jsonObject = resJosn.getJSONObject("data"); int errno = jsonObject.optInt("code"); String message = jsonObject.optString("msg"); - if(errno == 0){ - uploadCallBack.onSuccess(jsonObject.optString("info"),message); - }else{ + if (errno == 0) { + uploadCallBack.onSuccess(jsonObject.optString("info"), message); + } else { uploadCallBack.onFail(message); } } catch (JSONException e) { -- Gitblit v1.8.0