Please i have a json response String like this:
{"result":{"id":21456,"name":"3mm nail","type":"2" }}
and this is my code:
class rootObj{
List<Result> result;
}
public class Result {
@SerializedName("id")
public String idItem;
@SerializedName("name")
public String name;
}
public static void main(String[] args) throws Exception {
Gson gson = new Gson();
Result result = gson.fromJson(json,Result.class);
System.out.println(result.name);
}
But the result is null :( Thx in advance.
So.. This code is what i was aiming:
class ResultData{
private Result result;
public class Result {
private String id;
private String name;
}
}
...
Gson gson = new Gson();
ResultData resultData = new Gson().fromJson(json, ResultData.class);
System.out.println(resultData.result.id);
System.out.println(resultData.result.name);
Thx to BalusC gave me the idea about it. Java - Gson parsing nested within nested