0

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.

enter image description here

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;
}

}

2
  • Let's see the Carro class, it's probably incorrect. Commented May 4, 2017 at 20:42
  • Hola @Nasch Agregar clase a mi pregunta. Commented May 4, 2017 at 21:43

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.