Paru
Paru

Reputation: 57

Rxjava2 with retrofit

Am newly implementing the RxJava2 with retrofit , have implemented everything and wanted to get the result as JSONObeject

 Map<String, String> requestBody = new HashMap<>();
        requestBody.put("username", "xyz");
        requestBody.put("password", "abc");
   Single<ResponseBody> singleResponse = myService.loginWithParam(requestBody);

        singleResponse.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSingleObserver<ResponseBody>() {
                    @Override
                    public void onSuccess(ResponseBody response) {

                       response // this needs to be converted JsonObject 
                        loginResponse(response);
                    }

                    @Override
                    public void onError(Throwable e) {
                        System.out.println(e.getMessage());
                    }
                });

ResponseBody response how do i convert this as Json object, could't find any link in online .

Upvotes: 1

Views: 161

Answers (1)

Frank
Frank

Reputation: 12298

It might be easiest to get it as model object directly, retrofit can auto-parse the json into your model object: https://stackoverflow.com/a/31112346/1310343

Upvotes: 1

Related Questions