Retrofit 2 Android objects

0

I can not get the values at all.

The value received by JSON are these:

{
    "status": true,
    "valores": {
        "galo": {
            "nome": "galinho",
            "valor": 300,
            "ultima_consulta": 1386349203,
            "fonte": "galo.com.br"
        }
    }
}

I've tried everything, nothing's right.

RespostaServidor respostaServidor = response.body();

Valores valores = respostaServidor.getValores();
galo = valores.getGalo();

In class respostaServidor , it gets the status right, and the object, but then passes the null value to the rooster.

I do not know what else to do.

    
asked by anonymous 02.08.2016 / 20:13

2 answers

0

Hello. Let's say you did something like this:

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://exemplo.com")
            .build();

I also use retrofit. And to parse json for objects, I'm using GsonConverterFactory . Only by adding in gradle dependencies:

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

So building retrofit this way:

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://exemplo.com")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

If you're saying this in your code, that might be the problem.

It would be interesting to go into more detail on how you are working with the retrofit.

    
18.08.2016 / 21:57
0
public static final String BASE_URL = "http://portaljuventude.includetecnologia.com.br/api/";

private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

private static Retrofit.Builder builder
        =
        new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(new Gson()));

public static <S> S createService(Class<S> serviceClass) {
    Retrofit retrofit = builder.client(httpClient.build()).build();
    return retrofit.create(serviceClass);
}
    
22.11.2016 / 19:28