您的当前位置:首页正文

一图总结OkHttp

来源:华拓网

网上关于OkHttp的文章太多了,下面几篇文章不错

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;
    }

最后绘了一幅流程图作一个简单的总结

OkHttp框架图.png