I'm using Retrofit for integrating web services and when run my app controller going to Retrofit success block but how can i print ResponseBody in Json string formate
can some one help me please
Main Activity:-
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).
addConverterFactory(GsonConverterFactory.create()).build();
RetrofitGetAPI service = retrofit.create(RetrofitGetAPI.class);
retrofit.Call<List<CardTypes>> call = service.getProfileData();
call.enqueue(new Callback<List<CardTypes>>() {
@Override
public void onResponse(Response<List<CardTypes>> response, Retrofit retrofit) {
System.out.println("Response is=====>" + response.body());
}
@Override
public void onFailure(Throwable t) {
System.out.println("Failure response is====>");
}
});
}
RetrofitGetAPI:- ------------
public interface RetrofitGetAPI {
@GET("api/RetrofitProfileResponse")
Call<List<CardTypes>> getProfileData();
}
CardTypes:-
public class CardTypes {
private int paymenttypeid;
private String cardType;
public String getCardType() {
return cardType;
}
public void setCardType(String cardType) {
this.cardType = cardType;
}
public int getPaymenttypeid() {
return paymenttypeid;
}
public void setPaymenttypeid(int paymenttypeid) {
this.paymenttypeid = paymenttypeid;
}
}
Server response:-
[
{
"paymenttypeid": 1,
"cardType": "Master Card"
},
{
"paymenttypeid": 2,
"cardType": "VISA"
}
]