网上关于OkHttp的文章太多了,下面几篇文章不错
核心源码讲解:https://blog.piasy.com/2016/07/11/Understand-OkHttp
拦截链部分的巧妙设计 - 责任链模式://www.greatytc.com/p/8a157cb73434
封装 - 鸿神的OkHttp-Utils:https://github.com/hongyangAndroid/okhttputils
Gson解析
public class Response<T> {
public String MSG;
public int CODE;
public T RESULT;
}
public static <T> Response<T> parse(String jsonString, Class<T> clazz) {
Response<T> response = new Response<>();
JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject();
if (jsonObject.has("CODE") && jsonObject.has("MSG")) {
response.CODE = Integer.parseInt(jsonObject.get("CODE").toString());
response.MSG = jsonObject.get("MSG").toString();
if (jsonObject.has("RESULT")) {
response.RESULT = new Gson().fromJson(jsonObject.get("RESULT").toString(), clazz);
}
}
return response;
}