rxjavacalladapterfactory怎么gson解析json adapter外部为json数组

android - Rxjava + Retrofit Throwing OutOfMemoryError - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
When I use Retrofit with rxjava, some machine throwing OOM, this is log:
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
at java.lang.Thread.nativeCreate(Native Method)
at java.lang.Thread.start(Thread.java:1063)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1338)
at okhttp3.ConnectionPool.put(ConnectionPool.java:135)
at okhttp3.OkHttpClient$1.put(OkHttpClient.java:149)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:188)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:145)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.execute(RealCall.java:60)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
at rx.internal.operators.OperatorSubscribeOn$1$1$1.request(OperatorSubscribeOn.java:80)
at rx.Subscriber.setProducer(Subscriber.java:209)
at rx.internal.operators.OperatorSubscribeOn$1$1.setProducer(OperatorSubscribeOn.java:76)
at rx.Subscriber.setProducer(Subscriber.java:205)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:9861)
at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:221)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
my retrofit code:
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
if (BuildConfig.LOG_DEBUG)
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
interceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.retryOnConnectionFailure(true)
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
retrofit = new Retrofit.Builder()
.baseUrl(ConstantValue.URL + "/")
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
and my request code:
public interface GetUserFriendUsersService {
@FormUrlEncoded
@POST("IM/GetUserFriendUsers")
Observable&ResponseBody& getUserFriendUsers(@Field("UserID")String UserID);}
public void getUserFriendUsers(String userID, Subscriber&List&Users&& subscriber) {
retrofit.create(GetUserFriendUsersService.class)
.getUserFriendUsers(userID)
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.map(new HttpResultFunc())
.map(new Func1&JSONObject, List&Users&&() {
public List&Users& call(JSONObject jsonObject) {
List&Users& users = JSON.parseArray(jsonObject.getString("users"), Users.class);
if (users.size() == 0)
throw new CustomizeException("no data");
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
The .observeOn() should be in front of map(),and in back of unsubscribeOn()
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledcompile 'io.reactivex:rxandroid:1.1.0'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.squareup.okhttp3:okhttp:3.9.0'
compile 'com.squareup.okio:okio:1.13.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.facebook.fresco:fresco:0.12.0'
&uses-permission android:name=&android.permission.INTERNET&&&/uses-permission&
&uses-permission android:name=&android.permission.WRITE_EXTERNAL_STORAGE&&&/uses-permission&
&uses-permission android:name=&android.permission.READ_EXTERNAL_STORAGE&&&/uses-permission&
public interface IView {
void showList(List&MyBean.DataBean& list);
void showError(String e);
public class Api {
//http://mnews.gw.com.cn/wap/data/news/txs/page_1.json
public static final String PATH = &http://mnews.gw.com.cn/&;
public interface ApiService {
@GET(&wap/data/news/txs/page_{pages}.json&)
Observable&List&MyBean&& getdatas(@Path(&pages&)int pages) ;
public interface OnRequestListener {
void OnSuccess(List&MyBean.DataBean& list);
void OnError(String e);
public interface IModel {
void RequestData(String url,int page,OnRequestListener onRequestListener);
public class ListModel implements IModel {
public void RequestData(String url,int page, final OnRequestListener onRequestListener) {
//retrofit网络请求
Retrofit retrofit=new Retrofit
.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
ApiService apiService = retrofit.create(ApiService.class);
//结合rxjava
Observable&List&MyBean&& getdatas = apiService.getdatas(page);
getdatas.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber&List&MyBean&&() {
public void onCompleted() {
public void onError(Throwable e) {
onRequestListener.OnError(e.getMessage().toString());
public void onNext(List&MyBean& myBeen) {
List&MyBean.DataBean& data = myBeen.get(0).data;
onRequestListener.OnSuccess(data);
public interface IPresenter {
void loadList(String url,int page);
public class ListPresenter implements IPresenter {
private IView iView;
private IModel iModel;
public ListPresenter(IView iView) {
this.iView = iView;
iModel = new ListModel();
//model层与view层交互
public void loadList(String url,int page) {
iModel.RequestData(url,page, new OnRequestListener() {
public void OnSuccess(List&MyBean.DataBean& list) {
iView.showList(list);
public void OnError(String e) {
iView.showError(e);
public class MyBean {
public HeaderBean header;
public List&DataBean& data;
public static MyBean objectFromData(String str) {
return new Gson().fromJson(str, MyBean.class);
public static class HeaderBean { public int pagesize;
public String last;
public String pre;
public String next;
public int totalsize;
public String first;
public int totalpage;
public static HeaderBean objectFromData(String str) {
return new Gson().fromJson(str, HeaderBean.class);
public static class DataBean { public String summary;
public String img;
public String advTypeShare;
public String url;
public int countid;
public String id;
public String title;
public String otime;
public String source;
public String views;
public String resType;
public static DataBean objectFromData(String str) {
return new Gson().fromJson(str, DataBean.class);
在清单列表注册
android:name=&.App&
public class App extends Application {
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
public class MyAdapter extends RecyclerView.Adapter&MyAdapter.ViewHolder& {
private Context context;
private List&MyBean.DataBean& list;
public MyAdapter(Context context, List&MyBean.DataBean& list) {
this.context = context;
this.list = list;
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
return new ViewHolder(view);
public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {
holder.img.setImageURI(list.get(position).img);
holder.tv.setText(list.get(position).title);
public int getItemCount() {
return list.size();
public class ViewHolder extends RecyclerView.ViewHolder{
public SimpleDraweeView img;
public TextView tv;
public ViewHolder(View itemView) {
super(itemView);
img=itemView.findViewById(R.id.item_img);
tv=itemView.findViewById(R.id.tv);
public class MainActivity extends AppCompatActivity implements IView{
private RecyclerView recycler;
private MyAdapter myAdapter;
private int p=1;
private SwipeRefreshLayout swif;
private ListPresenter listPresenter;
private LinearLayoutManager linearLayoutManager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recycler = (RecyclerView) findViewById(R.id.recycler);
swif = (SwipeRefreshLayout) findViewById(R.id.swif);
linearLayoutManager = new LinearLayoutManager(MainActivity.this);
recycler.setLayoutManager(linearLayoutManager);
listPresenter = new ListPresenter(this);
listPresenter.loadList(Api.PATH,p);
public void showList(final List&MyBean.DataBean& list) {
//设置recyclerview展示
myAdapter = new MyAdapter(MainActivity.this, list);
recycler.setAdapter(myAdapter);
recycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
if (lastVisibleItemPosition == list.size() - 1) {
p++;
listPresenter.loadList(Api.PATH,p);
swif.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
public void onRefresh() {
p++;
listPresenter.loadList(Api.PATH,p);
swif.setRefreshing(false);
public void showError(String e) {
Toast.makeText(this, && + e, Toast.LENGTH_SHORT).show();
Log.e(&哈哈哈哈啊哈哈哈哈&, e);
//主页面布局
&android.support.v4.widget.SwipeRefreshLayout
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:id=&@+id/swif&&
&android.support.v7.widget.RecyclerView
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:id=&@+id/recycler&&&/android.support.v7.widget.RecyclerView&
&/android.support.v4.widget.SwipeRefreshLayout&
//Adapter布局
&com.facebook.drawee.view.SimpleDraweeView
android:id=&@+id/item_img&
android:layout_width=&150dp&
android:layout_height=&150dp&
android:layout_margin=&8dp&
fresco:failureImage=&@mipmap/ic_launcher& /&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:id=&@+id/tv&
android:text=&dfdf&
android:gravity=&center&/&
访问:4288次
排名:千里之外
原创:28篇
(5)(9)(5)(9)Rxjava、Retrofit返回json数据解析异常处理 - 简书
Rxjava、Retrofit返回json数据解析异常处理
每个App都避免不了要进行网络请求,从最开始的用谷歌封装的volley到再到android-async-http再到OKHttpUtils再到现在的和,从我自己用后的体验来看,用了retrofit和RxJava真的回不去了,回不去了,不去了,去了,了...(哈哈,本来还想分析下这四个的区别,网上这样的文章很多,我就没必要多添乱了-.-)。不多逼逼,下面开始正文。RxJava的学习资料1、Rxjava和Retrofit依赖导入:compile 'io.reactivex:rxandroid:1.2.0'
//Rxjava专门针对anroid封装的RxAndroidcompile 'io.reactivex:rxjava:1.1.5'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
//retrofitcompile 'com.squareup.retrofit2:converter-gson:2.0.2'
//gson convertercompile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
//Retrofit专门为Rxjava封装的适配器compile 'com.google.code.gson:gson:2.6.2'
//Gsoncompile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
//打印网络请求的log日志2、网络请求基类的配置建立一个工厂类public class ServiceFactory {
private final Gson mGsonDateF
public ServiceFactory(){
mGsonDateFormat = new GsonBuilder()
.setDateFormat("yyyy-MM-dd hh:mm:ss")
.create();
private static class SingletonHolder{
private static final ServiceFactory INSTANCE = new ServiceFactory();
public static ServiceFactory getInstance(){
return SingletonHolder.INSTANCE;
public &S& S createService(Class&S& serviceClass){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constant.BASE_URL) //Retrofit2 base url
必须是这种格式的:
.client(getOkHttpClient())
--------------------------添加Gson工厂变换器也就是不用管数据解析-----------------------------------
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
return retrofit.create(serviceClass);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
public void log(String message) {
//打印retrofit日志
Log.i("RetrofitLog","retrofitBack ======================= "+message);
private static final long DEFAULT_TIMEOUT = 10;
private OkHttpClient getOkHttpClient(){
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
//定制OkHttp
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
builder.writeTimeout(DEFAULT_TIMEOUT,TimeUnit.SECONDS);
builder.addInterceptor(loggingInterceptor);
//设置缓存
File httpCacheDirectory = new File(SDCardUtils.getRootDirectoryPath(),"这里是你的网络缓存存放的地址");
builder.cache(new Cache(httpCacheDirectory,10*));
return builder.build();
}}好了 下一步 我们要建一个网络请求的基类,一般网络请求返回的数据最外层的根式就是 code msg result,可变的就是result,所以我们把result的类型定义为一个泛型的public class HttpResult&T& extends BaseEntity {
private boolean isS
public void setMsg(String msg) {
this.msg =
public T getResult() {
public void setResult(T result) {
this.result =
public boolean isSuccess() {
return code == 200;
public int getCode() {
}}既然我们的网络请求是rxjava配合retrofit 下面就定义我们的网络请求订阅subscriberpublic abstract class HttpResultSubscriber&T& extends Subscriber&HttpResult&T&& {
public void onNext(HttpResult&T& t) {
if (t.isSuccess()) {
onSuccess(t.getResult());
_onError(t.getMsg().getCode());
public void onCompleted() {
public void onError(Throwable e) {
e.printStackTrace();
//在这里做全局的错误处理
if (e instanceof ConnectException ||
e instanceof SocketTimeoutException ||
e instanceof TimeoutException) {
//网络错误
_onError(-9999);
public abstract void onSuccess(T t);
public abstract void _onError(int status);}OK我们的网络请求基类已经完成啦!下面开始我们的网络请求首先我们定义一个接口(以登录为例):public interface LoginService {
//这个例子是post为例,如果想要了解其他的网络请求,请点击文章开始出的retrofit链接
@FormUrlEncoded
@POST(Constant.LOGIN_URL)
这里是你的登录url
//可以看到我们的登录返回的是一个Observable,它里面包含的使我们的网络请求返回的实体基类,
//而我们实体基类的result现在就是UserInfoEntity
Observable&HttpResult&UserInfoEntity&& login(@Field("mobile") String phone,
@Field("password") String pwd);}现在开始我们的网络请求啦public void login(String phone, String pwd) {
ServiceFactory.getInstance()
.createService(LoginService.class)
.login(phone,pwd)
.compose(TransformUtils.&HttpResult&UserInfoEntity&&defaultSchedulers())
.subscribe(new HttpResultSubscriber&UserInfoEntity&() {
public void onSuccess(UserInfoEntity userInfoEntity) {
//这是网络请求陈宫的回调
public void _onError(int status) {
//这是失败的回调 根据status做具体的操作
});}你以为这样就行了 ,
这样子确实没毛病,确实已经妥妥的了。可是,可是,事与愿违啊!!!3、具体解决办法一般情况这是我们的返回json格式:{
"code":200,
"msg":"成功",
"result":{}}我们刚才定义登录接口的时候 返回的实体基类例传入的是UserInfoEntity
这确实是没问题的 可是你们加入登录失败的时候返回的json数据格式是这样的怎么办?{
"code":300,
"msg":"成功",
"result":[]}失败的时候返回的实体又是一个数组,这样子就会抱一个json解析异常拿不多失败的状态码和提示信息OK其实我们的网络请求已经完成90%了,剩下的就是不重要的失败的时候回调了。方法一:(这是在后台兄弟好说话,而且不打人的情况下...当然这种好人,还是有的,不过这不是我们今天要讲的重点)我们可以让后台返回的json数据中的result永远是个数组。{
"code":300,
"msg":"成功",
"result":[]}方法二:
首先给大家看一个图片
这就是我们要下手的地方
上面我们添加的工厂变换器是导入的依赖 compile 'com.squareup.retrofit2:converter-gson:2.0.2' 这个提供的,那可能有人要问了,那我们不用这个用哪个啊,不着急,不着急。还好retrofit是支持自定义的ConverterFactory的下面我们就开始我们的自定义征程吧。---------------------------------------------------------华丽丽的分割线-----------------------------------------------1、自定义Gson响应体变换器public class GsonResponseBodyConverter&T& implements Converter&ResponseBody,T&{
private final G
private final T
public GsonResponseBodyConverter(Gson gson,Type type){
this.gson =
this.type =
public T convert(ResponseBody value) throws IOException {
String response = value.string();
//先将返回的json数据解析到Response中,如果code==200,则解析到我们的实体基类中,否则抛异常
Response httpResult = gson.fromJson(response, Response.class);
if (httpResult.getCode()==200){
//200的时候就直接解析,不可能出现解析异常。因为我们实体基类中传入的泛型,就是数据成功时候的格式
return gson.fromJson(response,type);
ErrorResponse errorResponse = gson.fromJson(response,ErrorResponse.class);
//抛一个自定义ResultException 传入失败时候的状态码,和信息
throw new ResultException(errorResponse.getCode(),errorResponse.getMsg());
}}2、自定义一个响应变换工厂 继承自 retrofit的 converter.Factorypublic class ResponseConverterFactory extends Converter.Factory {
public static ResponseConverterFactory create() {
return create(new Gson());
public static ResponseConverterFactory create(Gson gson) {
return new ResponseConverterFactory(gson);
private final G
private ResponseConverterFactory(Gson gson) {
if (gson == null) throw new NullPointerException("gson == null");
this.gson =
public Converter&ResponseBody, ?& responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
//返回我们自定义的Gson响应体变换器
return new GsonResponseBodyConverter&&(gson, type);
public Converter&?, RequestBody& requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
//返回我们自定义的Gson响应体变换器
return new GsonResponseBodyConverter&&(gson,type);
}}//然后将上面的GsonConverterFactory.create()替换成我们自定义的ResponseConverterFactory.create()然后将上面的GsonConverterFactory.create() 替换成我们自定义的ResponseConverterFactory.create()。public &S& S createService(Class&S& serviceClass){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constant.BASE_URL)
.client(getOkHttpClient())
//.addConverterFactory(GsonConverterFactory.create())
//然后将上面的GsonConverterFactory.create()替换成我们自定义的ResponseConverterFactory.create()
.addConverterFactory(ResponseConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
return retrofit.create(serviceClass);}再然后,最后一个然后啦(-.-)在我们的自定义的Rxjava订阅者 subscriber中的onError()中加入我们刚才定义的ResultException。@Overridepublic void onError(Throwable e) {
e.printStackTrace();
//在这里做全局的错误处理
if (e instanceof ConnectException ||
e instanceof SocketTimeoutException ||
e instanceof TimeoutException) {
//网络错误
_onError(-9999);
} else if (e instanceof ResultException) {
//自定义的ResultException
//由于返回200,300返回格式不统一的问题,自定义GsonResponseBodyConverter凡是300的直接抛异常
_onError(((ResultException) e).getErrCode());
System.out.println("---------errorCode-------&"+((ResultException) e).getErrCode());
}}这次是真的完成了我们的json数据解析异常的处理,其实我们的解决办法是解析了两次,第一次解析的时候我们的Response中只有只是解析了最外层的 code 和 msg
,result中的是没有解析的。response中的code==200,直接将数据解析到我们的实体基类中。如果code!=200时,直接抛自定义的异常,直接会回调到subscriber中的onError()中。虽然进行了两次解析,但是第一次只是解析了code,和msg 对于效率的影响其实并不大,在功能实现的基础上一点点效率的影响(而且这个影响是微乎其微的-.-)其实无伤大雅的。
今天吃虫了么(ˉ﹃ˉ)
用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金Cover 有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? ... Android 获取 View 宽高的常用正确方式,避免为零 - 掘金相信有很多朋友...
用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? ... Android 获取 View 宽高的常用正确方式,避免为零 - 掘金 相信有很多...
Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线)。分布式系统的协调导致了样板模式, 使用Spring Cloud开发人员可以快速地支持实现这些模式的服务和应用程序。他们将在任何分布式...
持续更新中,欢迎大家指正交流 实战解析Retrofit 官方链接http://square.github.io/retrofit/github地址https://github.com/square/retrofit 1. 作用 官方描述:对网络请求的封装.Use annot...
本文出处 :Tamic文/ http://www.jianshu.com/p/bf Rxjava +Rterofit 需要掌握的几个技巧 RxJava入门和详解请移步 比较有名的《RxJAVA详解》,这里继续前篇一系列的介绍一些容易忽略的技巧. Retr...
一别天南北,引马路东西。来去各有时,聚散应无期。
垫底辣妹终于还是看完了,多少有点意犹未尽,虽然过去的某一时刻,R国人真的不怎么样,但21世纪的电影还是拍的很不错的!!! 一句话形容这部电影:纸质版的‘佐藤大和’上银幕了。 佐藤大和就是那个写了《狡猾读书法的》的逊咖主角。他和电影中美丽的女主角一样,都是“逊咖”,结果都考上...
今天再次看了吸引力法则这部电影,每一次都有不同的收获,吸引力告诉我们,我们要有自己的目标并时刻提醒自己努力完成目标,这样我们就一定能够成功!你要改变现状,就要先改变你的想法。要用积极的态度面对一切不顺心的事情,你善待自己,充满快乐,就会影响你周边的人或事,设定下目标,付诸于...
在短短的一生里鼓起勇气做想做的事成为想成为的自己 - 01 - 七十七天,一千八百四十八小时,十一万零八百八十分钟,六百六十五万两千八百秒,杨柳松用了这些时间穿越了羌塘无人区,那片北方未知的土地。 在那片真正属于他一个人的荒原,没有束缚,他可以恣意追求自由。没有人能预料到,...
轻轻撩起记忆的发梢 不经意闪入你的俏皮的笑貌 于是,思绪冉冉飘扬 好不容易才记起你有一颗泪痣 却绞尽脑汁也无法想起 到底是在左还是右 于是我不禁苦恼 难道是我对青春的感情不忠了 很不理解这样的自己 明明当年对你如此痴迷 如今,却是完整的你都无法忆起 只是记得初中的你 是如此...

我要回帖

更多关于 calladapter.factory 的文章

 

随机推荐