Gson fromJson() returns object with null attrubutes

后端 未结 3 1281
醉话见心
醉话见心 2021-01-17 14:58

I\'m trying to create some Java objects using this line:

Quiz currentQuiz = gson.fromJson(json, Quiz.class);

But the all I get is this:

3条回答
  •  孤街浪徒
    2021-01-17 15:23

    From your json: i see that, at the root level it is something like

    {quiz:{quizObject having ref,etc.,}}

    So, you need to get one level down to start parsing using gson.

    So, try this out,

    JSONObject quizObject = json.get("quiz");
    
    Quiz currentQuiz = gson.fromJson(quizObject.toString(), Quiz.class);
    

提交回复
热议问题