1

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 .

Paru
  • 57
  • 1
  • 7

1 Answers1

1

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

Frank
  • 12,010
  • 8
  • 61
  • 78
  • Thanks @Frank, its works as model object, but is it possible to get as JSON object? – Paru Sep 01 '17 at 06:26
  • Maybe this will help: https://stackoverflow.com/questions/32617770/how-to-get-response-as-string-using-retrofit-without-using-gson-or-any-other-lib – Frank Sep 01 '17 at 08:08