I have a Json array like this
String carJson = "[{ \"brand\" : \"Mercedes\", \"doors\" : 5 }, { \"brand\" : \"Mercedes\", \"doors\" : 5 }]";
so far i have done this
Car cars = gson.fromJson(carJson,Car[].class);
and my car class is
private static class Car {
private String brand = null;
private int doors = 0;
public String getBrand() { return this.brand; }
public void setBrand(String brand){ this.brand = brand;}
public int getDoors() { return this.doors; }
public void setDoors (int doors) { this.doors = doors; }
}
But its not working. How can I convert this string array to Java array? And how to retrieve the elements using the keys?