How to serialize a JSON object child into a field?

前端 未结 6 872
一生所求
一生所求 2021-01-19 10:22

I have a JSON object that looks like this

{
  \"foo\":{
      \"bar\":\"bar\",
      \"echo\":\"echo\"
  }
}

But then my Java object looks

6条回答
  •  孤独总比滥情好
    2021-01-19 11:02

    You have to write a model class with all the variables and then you can use

    Gson gson=new Gson();
    ClassName objectName=gson.fromJson(yourJsonObject,ClassName.class);
    

    Here objectName contains your json

提交回复
热议问题