I am working on a REST application and the response I get from the server is a string of Json with the following format:
[{"car": "ford"}, {"car": "nissan"}, {"car": "bmw"}]
I want to use Gson to retrieve information by key through each element in that list, but because it is returned as a string I'm not sure how to go about it.
If I simply had the response be:
String json = {"car:": "ford"};
Then I could retrieve the car's value as follows:
Map<String,Object> result = new Gson().fromJson(json, Map.class);
System.out.println( result.get( "car" ) );
But because the original string is a list of json's it's more difficult.
Help appreciated. Ideally still using the Gson class
Thanks
car? If so, does using a map make sense? This looks much more like a list of objects to me with each object having a car field.