0

If I have JSON DATA like:

{
   "status":200,

   "carList":[
       {
          "carId":121,
          "carName":"Cat",
      },
      {
         "carId":122,
         "carName":"Snek",
      }
   ]
}

I want to Use GSON to create the objects by:

Cars cars = gson.fromJson(api.response(), Cars.class);

Using the two classes like this:

Class Cars{
    public String status;
    public Hashmap<String, Car> carList;
}

Class Car{
    public String carId;
    public String carName;
}

From what I am reading my problem is putting an object inside of the HashMap.

At the end of the day I need to be able to loop the "carLis" to display it in a table but I am not sure what my approach should be.

silversunhunter
  • 1,219
  • 2
  • 12
  • 32

1 Answers1

1

carList is an Array of Objects and not a hashmap. Try changing the type of carList to ArrayList

Class Cars{
    public String status;
    public ArrayList<Car> carList;
}

You can loop over the ArrayList for the elements