Hi, I am trying to parse the following JSON response into List
{"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();
}
AbebeerApi implementation
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("end_point_url")
.build();
AbebeerApi service = retrofit.create(AbebeerApi.class);
And call the created service
List<SingleBeer> beers = service.listBeers();
I get no answer on the beer list. My application is closing and I am not getting any information in logcat.
This is my POJO class
public class SingleBeer {
int id;
String nombre;
String localidad;
String provincia;
}
Can someone help me? Thank you in advance
EDIT: I give you my PHP code if something is wrong with it.
if (mysql_num_rows($result) > 0) {
$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"];
array_push($response["beers"], $beers);
}
$response["succes"] = 1;
echo json_encode($response);
mysql_close($localhost);
} else {
$response["success"] = 0;
$response["message"] = "No beers have found";
echo json_encode($response);
mysql_close($localhost);
}
EDIT 2: I resolved the issue with this post
https://stackoverflow.com/a/4646263
I created the LenientGsonConverter class, which I added in the setConverter method, to my RestAdapter