How do I convert a JSONObject to class object?

后端 未结 5 1228
南旧
南旧 2020-12-05 18:19

I need to convert a JSONObject to a Location object using gson libraries for an android project of mine. I\'m not sure on how to do this. Can anyone help me with this. Thank

5条回答
  •  不知归路
    2020-12-05 18:56

    Here's a tutorial for GSON - I think it should help bolster your understanding. Essentially the parsing is done like this:

    String mJsonString = "...";
    JsonParser parser = new JsonParser(); 
    JsonElement mJson =  parser.parse(mJsonString);
    Gson gson = new Gson();
    MyDataObject object = gson.fromJson(mJson, MyDataObject.class);
    

提交回复
热议问题