Create a class to accept the Cart array
public class ResponseObject {
public Data[] cart;
}
Then create a class Data to get the fields inside the array and create its getter methods.
public class Data{
public String id;
public String ProductId;
public String UserRegistrationId;
public String getId() {
return id;
}
public String getProductId() {
return ProductId;
}
public String getUserRegistrationId() {
return UserRegistrationId;
}
}
Create a Api class to store your services in as follows:
public interface AllApi {
@FormUrlEncoded
@POST("<your php / api url here>")
Call<ReturnedResponsePojo> getCartItems(@Field("Order_Id") String Order_Id);
}
Then Accept the data from server using retrofit like
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Config.APP_SERVER_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
AllApi mApiService = retrofit.create(AllApi.class);
Call<ResponseObject> mService = mApiService.getCartItems("<Order ID here>");
mService.enqueue(new Callback<ResponseObject>() {
@Override
public void onResponse(Call<ResponseObject> call, Response<ResponseObject> response) {
ResponseObject jsonResponse = response.body();
ArrayList<Data> dataArray = new ArrayList<>(Arrays.asList(jsonResponse.getCart()));
*** Write your required code here ***
}
@Override
public void onFailure(Call<ResponseObject> call, Throwable t) {
}
});