-2

I developed android application with retorfit 2.0. I tweeter in our application. I am getting json array format data from url when check in browser. I am getting response in my application like code: 200ok and responce is like : repoces@012345 printed as raw data. How can I print response as array format.

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://cdn.syndication.twimg.com/")
                .addConverterFactory(GsonConverterFactory.create())

                .build();

        RequestInterface requestInterface = retrofit.create(RequestInterface.class);


        Call<ResponseBody> response = requestInterface.gettwetter("vinodh654");

        response.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Log.d("Tweeter Respose",response.code()+" "+response.message()+" "+response.body().toString());


            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Log.d("Tweeter Respose","Fail");
            }
        });
vinodh kumar
  • 83
  • 1
  • 9
  • `response.body().string()` will help you. – KuLdip PaTel Nov 16 '17 at 04:39
  • There is a library that shows your request and rsponse with retrofit, It is released by Square itself. Check aldok's answer for the reference https://stackoverflow.com/questions/32965790/retrofit-2-0-how-to-print-the-full-json-response – Somesh Kumar Nov 16 '17 at 04:42

4 Answers4

0

To get the JSON use

response.body().string()
raggedycoder
  • 495
  • 1
  • 6
  • 18
0

You can print that using response.body().string() as follows:

  response.enqueue(new Callback<ResponseBody>() {
     @Override
     public void onResponse(Call<ResponseBody> call,Response<ResponseBody> response) {
            String data = response.body().string(); // It will get the response 
            Log.d("Tweeter Respose",response.code()+" "+response.message()+" "+data;
     }

     @Override
     public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.d("Tweeter Respose","Fail");
     }
  });
Yamini Balakrishnan
  • 2,361
  • 16
  • 24
0

Try this

 @Override
         public void onResponse(Call<ResponseBody> call,Response<ResponseBody> response) {
                String responseString = response.body().string(); 
                Log.d("Response",response.code()+" "+response.message()+" "+data;
         }
Quick learner
  • 10,632
  • 4
  • 45
  • 55
0

You can print that json response like this - new Gson().toJson(response.body())

response.enqueue(new Callback<ResponseBody>() {
     @Override
     public void onResponse(Call<ResponseBody> call,Response<ResponseBody> response) {
            String data = new Gson().toJson(response.body()); // It will get the response 
            Log.d("Response",response.code()+" "+response.message()+" "+data;
     }

     @Override
     public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.d("Response","Fail");
     }
  });
Sanjay Kushwah
  • 190
  • 1
  • 9