Anshuman Pattnaik Anshuman Pattnaik - 1 year ago 154
JSON Question

How to get a raw Retrofit response string?

I am working on Retrofit, but I am stuck on one thing: how do I get the raw JSON on the response body.

public interface ViewMenuItems {
Call<ResponseBody> listRepos(@Url String url);

ViewMenuItems viewMenuItems = ApiClient.getClient().create(ViewMenuItems.class);
Call<ResponseBody> responseBodyCall = viewMenuItems.listRepos(Webservices.MERCHANT + merchantId + Webservices.MENU_ITEMS_LASTMODIFIED);

responseBodyCall.enqueue(new Callback<ResponseBody>() {
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.d("MenuItems", "Response :: " + response.body().toString());

public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.d("MenuItems", "Exception :: " + t.toString());

But in the "MenuItems" log I am not getting the JSON response, it's coming something like this

MenuItems: Response :: retrofit2.Response@e292dd4

Please kindly go through my post and suggest me some solution.

Answer Source

Try to use body().string() instead of body().toString()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download