How to parse nested JSON using GSON

后端 未结 3 1418
自闭症患者
自闭症患者 2021-01-28 00:41

I am currently making a get request using volley and in onResponse i am trying to parse the jsonObject using gson to my model.

JSON Returned after the request is made:

3条回答
  •  失恋的感觉
    2021-01-28 01:09

    i have a really easy approach for you:

    first of all create the main model: and the other one for "data"

    public class FeedBackModel {
        int success;
        String message;
        DataModel data;
    
    }
    
    public class DataModel {
    
        String company;
        String email;
        //etc ...
    }
    

    // create getter& setter for variables

    then when you got json, parse it like this:

                Gson gson = new Gson();
                Type CollectionType = new TypeToken() {
                }.getType();
                FeedBackModel FeedBack = gson.fromJson(json, CollectionType);
    

提交回复
热议问题