Skip to content

List All Data Using Retrofit/OkHttp With Response List

I have some codes that fetch some data from my API. My question is how can I list all the objects that I fetched before without using this jsonData.get(0), I expect something like jsonData.get(i), so I assume using something like below, but I can’t use it, so how can I do that? Thanks.

for (int i=0;i<jsonData.length();i++){

List<Promo> jsonData = response.body();
String promoID = jsonData.get(0).getId_promo();
String promoTipe = jsonData.get(0).getPromo_type();
String promoValue = jsonData.get(0).getValue_based();
String promoName = jsonData.get(0).getPromo_name();

With POJO class that looks like this

public class Promo  {
    private String id_promo;
    private String promo_name;
    private String promo_type;
    private String value_based;
    private String quota;
    private String id_event;
    private String description;

    public String getId_promo() {
        return id_promo;

    public void setId_promo(String id_promo) {
        this.id_promo = id_promo;

    public String getPromo_name() {
        return promo_name;

Call<List<Promo>> getPromo(
        @Field("id_event") String id_event,
        @Field("total_buyer") String totalBuyer,
        @Field("id_user") String id_user,
        @Field("id_ticket") String id_ticket);



Using for loop like below solved my problem

for (int i=0;i<jsonData.size();i++){}
10 People found this is helpful