Commit ee9add31 by amateur

1

1 parent af3c77bc
...@@ -20,6 +20,11 @@ import okhttp3.Response; ...@@ -20,6 +20,11 @@ import okhttp3.Response;
public abstract class RequestBack<T> { public abstract class RequestBack<T> {
void onParseResponse(Call call, Response response, Exception e) { void onParseResponse(Call call, Response response, Exception e) {
if (null != e) {
e.printStackTrace();
this.onResponse(StateEnum.FAIL, null, e.getMessage());
return;
}
int resCode = response.code(); int resCode = response.code();
if (resCode < 200 && resCode >= 300) { if (resCode < 200 && resCode >= 300) {
String message = String.format("网络错误(%d)", resCode); String message = String.format("网络错误(%d)", resCode);
...@@ -42,7 +47,7 @@ public abstract class RequestBack<T> { ...@@ -42,7 +47,7 @@ public abstract class RequestBack<T> {
JSONObject res = JSON.parseObject(string); JSONObject res = JSON.parseObject(string);
int status = res.getInteger("status"); int status = res.getInteger("status");
if (status == 200) { if (status == 200) {
String json = res.getString("obj"); String json = res.getString("data");
Log.d("onParseResponse", "onParseResponse: " + json); Log.d("onParseResponse", "onParseResponse: " + json);
Type type = this.getClass().getGenericSuperclass(); Type type = this.getClass().getGenericSuperclass();
if (type instanceof ParameterizedType) { if (type instanceof ParameterizedType) {
...@@ -51,7 +56,7 @@ public abstract class RequestBack<T> { ...@@ -51,7 +56,7 @@ public abstract class RequestBack<T> {
if (this.isTypeCalss(arguments[0], String.class)) { if (this.isTypeCalss(arguments[0], String.class)) {
this.onResponse(StateEnum.OK, (T) json, null); this.onResponse(StateEnum.OK, (T) json, null);
} else if (this.isTypeCalss(arguments[0], JSONObject.class)) { } else if (this.isTypeCalss(arguments[0], JSONObject.class)) {
JSONObject data = res.getJSONObject("obj"); JSONObject data = res.getJSONObject("data");
this.onResponse(StateEnum.OK, (T) data, null); this.onResponse(StateEnum.OK, (T) data, null);
} else { } else {
T data = JSON.parseObject(json, type); T data = JSON.parseObject(json, type);
...@@ -61,7 +66,7 @@ public abstract class RequestBack<T> { ...@@ -61,7 +66,7 @@ public abstract class RequestBack<T> {
this.onResponse(StateEnum.FAIL, null, "解析异常"); this.onResponse(StateEnum.FAIL, null, "解析异常");
} }
} else { } else {
String message = res.getString("msg"); String message = res.getString("statusText");
this.onResponse(StateEnum.FAIL, null, message); this.onResponse(StateEnum.FAIL, null, message);
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!