在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):wangchenyan/ponyexpress开源软件地址(OpenSource Url):https://github.com/wangchenyan/ponyexpress开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):小马快递前言这是我第一个独立完成的项目,时隔多年又把它拿出来重构了一下代码。
简介小马快递,您的好帮手。查询并跟踪快递,快递信息及时掌握。 更新说明
下载地址项目公开API
开源技术关键代码网络请求
封装GsonRequest public class GsonRequest<T> extends Request<T> {
private Class<T> mClass;
private Response.Listener<T> mListener;
private Gson mGson;
public GsonRequest(int method, String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
super(method, url, errorListener);
mClass = clazz;
mListener = listener;
mGson = new Gson();
}
public GsonRequest(String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
this(Method.GET, url, clazz, listener, errorListener);
}
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
String jsonString;
try {
jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return Response.success(mGson.fromJson(jsonString, mClass), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return Response.error(new ParseError(e));
}
}
@Override
protected void deliverResponse(T response) {
mListener.onResponse(response);
}
} 截图关于作者掘金:https://juejin.im/user/2313028193754168 License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论