RxJava2.x操作符

  • map
    实现单个数据的转换。
    实例:把网络中ResponseBody用Gson转换为相对应的数据实体再下发给子类。
  .map(new Function() {
           @Override
           public MobileAddress apply(@NonNull Response response) throws Exception {
            if (response.isSuccessful()) {
                ResponseBody body = response.body();
                if (body != null) {
                    Log.e(TAG, "map:转换前:" + response.body());
                    return new Gson().fromJson(body.string(), MobileAddress.class);
                }
            }
                    return null;
                }
            }).observeOn(AndroidSchedulers.mainThread())
            .doOnNext(new Consumer() {
             @Override
             public void accept(@NonNull MobileAddress s) throws Exception {
                 Log.e(TAG, "doOnNext: Number:" + s.getNumbser() + "\n");
             }
         })

你可能感兴趣的:(RxJava2.x操作符)