Reputation: 1
they are new to Retrofit and I am trying to get data from a JSON using the ID, with the post method, but I throw this arror.
This is the JSON I'm trying to consume`
[{"idPlakas":"6","latitud":"19.681984","longitud":"-101.171496","titulo":"markador"}]
Here is my post method making the request by ID.
@FormUrlEncoded
@POST("/Cprincipal/obtener_carro/")
void obtCarro(@Field("idPlakas") int idPlakas, Callback<Carro> callback);
I perform the following code to receive the object and the information that it has, and this same madarla to another method that would create a marker. But when running my application does not enter that method and I get the error.
public void actualizarMarcador() {
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://192.168.1.70/formularios").build();
CoordenadaServicio serv = restAdapter.create(CoordenadaServicio.class);
serv.obtCarro(placaM, new Callback<Carro>() {
@Override
public void success(Carro carro, Response response) {
if (carroObjeto!=null){
carroObjeto=null;
}
carroObjeto = new Carro();
carroObjeto.setIdPlakas(carro.getIdPlakas());
carroObjeto.setLongitud(carro.getLongitud());
carroObjeto.setLatitud(carro.getLatitud());
carroObjeto.setTitulo(carro.getTitulo());
generarMarker(carroObjeto);
}
@Override
public void failure(RetrofitError error) {
Log.e("mapa", " failed "+ String.valueOf(error));
}
});
}
this is my class
class Carro {
@SerializedName("idPlakas")
private int idPlakas;
public int getIdPlakas() {
return idPlakas;
}
public void setIdPlakas(int idPlakas) {
this.idPlakas = idPlakas;
}
@SerializedName("latitud")
private Double latitud;
public Double getLatitud() {
return latitud;
}
public void setLatitud(Double latitud) {
this.latitud = latitud;
}
@SerializedName("longitud")
private Double longitud;
public Double getLongitud() {
return longitud;
}
public void setLongitud(Double longitud) {
this.longitud = longitud;
}
@SerializedName("titulo")
private String titulo;
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
}
Upvotes: 0
Views: 2024
Reputation: 1125
Your Callback
expects a single Carro
object.
Callback<Carro> callback
but the response you have posted is a Json array (note the square brackets)
[{"idPlakas":"6","latitud":"19.681984","longitud":"-101.171496","titulo":"markador"}]
so you need to change your callback to expect a List<Carro>
Upvotes: 1