|
@@ -3,12 +3,12 @@ package com.benyanyi.okhttp.call;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
|
import com.benyanyi.okhttp.config.CallType;
|
|
import com.benyanyi.okhttp.config.CallType;
|
|
-import com.benyanyi.okhttp.util.OkHttpLog;
|
|
|
|
|
|
+import com.benyanyi.okhttp.listener.OnOkHttpListener;
|
|
import com.benyanyi.okhttp.util.CacheUtils;
|
|
import com.benyanyi.okhttp.util.CacheUtils;
|
|
import com.benyanyi.okhttp.util.FormatUtil;
|
|
import com.benyanyi.okhttp.util.FormatUtil;
|
|
import com.benyanyi.okhttp.util.Internet;
|
|
import com.benyanyi.okhttp.util.Internet;
|
|
import com.benyanyi.okhttp.util.InternetBean;
|
|
import com.benyanyi.okhttp.util.InternetBean;
|
|
-import com.benyanyi.okhttp.listener.OnOkHttpListener;
|
|
|
|
|
|
+import com.benyanyi.okhttp.util.OkHttpLog;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonParser;
|
|
import com.google.gson.JsonParser;
|
|
@@ -138,7 +138,7 @@ class BeanCall<T> {
|
|
|
|
|
|
private void success(Response response, ObservableEmitter<T> emitter) throws IOException {
|
|
private void success(Response response, ObservableEmitter<T> emitter) throws IOException {
|
|
ResponseBody body = response.body();
|
|
ResponseBody body = response.body();
|
|
- if (body != null) {
|
|
|
|
|
|
+ if (body != null && response.code() == 200) {
|
|
if (response.isSuccessful()) {
|
|
if (response.isSuccessful()) {
|
|
if (response.networkResponse() != null) {//网络请求有数据
|
|
if (response.networkResponse() != null) {//网络请求有数据
|
|
String str = body.string();
|
|
String str = body.string();
|
|
@@ -163,7 +163,7 @@ class BeanCall<T> {
|
|
String str = message;
|
|
String str = message;
|
|
OkHttpLog.d(str);
|
|
OkHttpLog.d(str);
|
|
String html = "<!DOCTYPE HTML>";
|
|
String html = "<!DOCTYPE HTML>";
|
|
- if (!str.toUpperCase().contains(html)) {
|
|
|
|
|
|
+ if (FormatUtil.isNotEmpty(str) && !str.toUpperCase().contains(html)) {
|
|
if (FormatUtil.isNotEmpty(mCacheName)) {
|
|
if (FormatUtil.isNotEmpty(mCacheName)) {
|
|
CacheUtils.getInstance(context).setCacheToLocalJson(mCacheName, str);
|
|
CacheUtils.getInstance(context).setCacheToLocalJson(mCacheName, str);
|
|
}
|
|
}
|
|
@@ -196,6 +196,9 @@ class BeanCall<T> {
|
|
private T dataToT(String data) {
|
|
private T dataToT(String data) {
|
|
String str = data;
|
|
String str = data;
|
|
OkHttpLog.d(str);
|
|
OkHttpLog.d(str);
|
|
|
|
+ if (FormatUtil.isEmpty(str)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
T t = null;
|
|
T t = null;
|
|
boolean boo = ("<".equals(str.substring(0, 1)) || "[".equals(str.substring(0, 1)))
|
|
boolean boo = ("<".equals(str.substring(0, 1)) || "[".equals(str.substring(0, 1)))
|
|
&& ("\"".equals(str.substring(1, 2)) || "[".equals(str.substring(1, 2)));
|
|
&& ("\"".equals(str.substring(1, 2)) || "[".equals(str.substring(1, 2)));
|
|
@@ -206,23 +209,17 @@ class BeanCall<T> {
|
|
OkHttpLog.e(e.getMessage());
|
|
OkHttpLog.e(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- JsonParser jsonParser = new JsonParser();
|
|
|
|
- JsonElement parse = jsonParser.parse(str);
|
|
|
|
- if (parse.isJsonObject()) {
|
|
|
|
- try {
|
|
|
|
|
|
+ try {
|
|
|
|
+ JsonParser jsonParser = new JsonParser();
|
|
|
|
+ JsonElement parse = jsonParser.parse(str);
|
|
|
|
+ if (parse.isJsonObject()) {
|
|
t = new Gson().fromJson(str, tClass);
|
|
t = new Gson().fromJson(str, tClass);
|
|
- } catch (Exception e) {
|
|
|
|
- OkHttpLog.e(e.getMessage());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- try {
|
|
|
|
|
|
+ } else {
|
|
t = new Gson().fromJson(str, tClass);
|
|
t = new Gson().fromJson(str, tClass);
|
|
- } catch (Exception e) {
|
|
|
|
- OkHttpLog.e(e.getMessage());
|
|
|
|
}
|
|
}
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ OkHttpLog.e(e.getMessage());
|
|
}
|
|
}
|
|
return t;
|
|
return t;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|