13
I am trying to convert a JSON string into a Java object used by Gson.
This is the json I get from the webservice:
{"concurso":
{
"numero":1499,
"data_sorteio":"01\/06\/2013",
"dezenas":[8,22,26,33,37,54]
}
}
This is my pojo class:
public class Concurso {
private int numero;
private String dataSorteio;
private int[] dezenas;
public Concurso() {
}
@Override
public String toString() {
return numero + " - " + dataSorteio;
}
}
Here is how I am trying to convert String Json to Java
Gson gson = new Gson();
Concurso concurso = gson.fromJson(stringJson, Concurso.class);
Log.v("teste", concurso.toString());
Here’s the way out of Logcat
02-16 21:01:47.923 20796-20810/com.n3t0l0b0.blogspot.megasena.ativitys E/teste﹕ 0 - null
There is no error in anything, only that the conversion of String Json to the java object simply does not occur, object is null.
I believe you need to create the get and set methods of the attributes.
– Beterraba