Rxjava网络嵌套

public void lastRequest(final HttpListener mHttpListener) {
    Map<String, String> map = new HashMap<>();
    map.put("phone", "13568574500");
    map.put("pwd", "123456");
    final Observable<ResponseBody> post = this.httpService.post("small/user/v1/login", map);
    post.subscribeOn(Schedulers.io())
            .observeOn(Schedulers.io())
            .doOnNext(new Consumer<ResponseBody>() {
                @Override
                public void accept(ResponseBody responseBody) {
                    try {
                        String string = responseBody.string();
                        Gson gson = new Gson();
                        LoginBean loginBean = gson.fromJson(string, LoginBean.class);
                        headMap = new HashMap<>();
                        headMap.put("userId", loginBean.getResult().getUserId() + "");
                        headMap.put("sessionId", loginBean.getResult().getSessionId());
                        JSONObject object = new JSONObject();
                        object.put("commodityId", 5);
                        object.put("count", 156);
                        JSONArray array = new JSONArray();
                        array.put(object);
                        Log.e("jsonStri", array.toString());
                        put = HttpUtils.this.httpService.put("small/order/verify/v1/syncShoppingCart", headMap, array.toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).subscribeOn(Schedulers.io())
            .flatMap(new Function<ResponseBody, ObservableSource<ResponseBody>>() {
                @Override
                public ObservableSource<ResponseBody> apply(ResponseBody responseBody) {
                    return put;
                }
            }).doOnNext(new Consumer<ResponseBody>() {
        @Override
        public void accept(ResponseBody responseBody) {

            try {
                Gson gson = new Gson();
                JoinShopping joinShopping = gson.fromJson(responseBody.string(), JoinShopping.class);
                if (joinShopping.getStatus().equals("0000")) {
                    Log.e("加入购物车成功", "----");
                    shopping = HttpUtils.this.httpService.get("small/order/verify/v1/findShoppingCart", headMap);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).flatMap(new Function<ResponseBody, ObservableSource<ResponseBody>>() {
        @Override
        public ObservableSource<ResponseBody> apply(ResponseBody responseBody) {
            return shopping;
        }
    }).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<ResponseBody>() {
                @Override
                public void accept(ResponseBody responseBody) {
                    try {
                        mHttpListener.success(responseBody.string());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });

}
上一篇:springboot @ResponseBody 返回对象报错解决


下一篇:Spring component detection logic