Hi I'm trying to parse into a List the following JSON response
{"beers":[{"id":"1","nombre":"Larzobispa","localidad":"Alcorcon","provincia":"Madrid"},{"id":"2","nombre":"La Cibeles","localidad":"Madrid","provincia":"Madrid"}]}
Im using the following code
My interface
public interface AbebeerApi {
@GET("/beer_app/beers")
List<SingleBeer> listBeers();
}
Implementation of the AbebeerApi
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("end_point_url")
.build();
AbebeerApi service = retrofit.create(AbebeerApi.class);
And the call for the created service
List<SingleBeer> beers = service.listBeers();
I dont get any response in beers list. My app close and I get no information in the logcat.
This is my POJO class
public class SingleBeer {
int id;
String nombre;
String localidad;
String provincia;
//getters and setters
}
Could some one help me? Thank you in advance
EDIT: I let you my php code in case there is something wrong with it
if (mysql_num_rows($result) > 0) {
// looping through all results
$response["beers"] = array();
while ($row = mysql_fetch_array($result)) {
$beers = array();
$beers["id"] = $row["id"];
$beers["nombre"] = $row["nombre"];
$beers["localidad"] = $row["localidad"];
$beers["provincia"] = $row["provincia"];
// push single product into final response array
array_push($response["beers"], $beers);
}
// success
$response["succes"] = 1;
// echoing JSON response
echo json_encode($response);
mysql_close($localhost);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No beers have found";
// echo no users JSON
echo json_encode($response);
mysql_close($localhost);
}
EDIT 2: I solved the problem with this post https://stackoverflow.com/a/27698866/4669063
I created the LenientGsonConverter class I added in the setConverter method to my RestAdapter