0

This json object can be very very large sometimes, I would like to parse it with GSON but I do not quite get how the format of my java objects should be to parse them.

What would really help me are some very contextual examples, given this object, how would I form my java model objects to hold the data in a gson.fromJSON method? My current objects get filled with "null"

I explain the simplicity of the object at the bottom

{
  response: {
    user_is_following: 0,
    name: "Tennesee",
    submitted_requests: 429,
    completed_requests: 34,
    request_types: {
        c_id: 1064,
        request_types: [
            {
                objectKey: {
                    id: 15699,
                    name: "Complaint",
                    has_custom_fields: 0,
                    disable_title: 0,
                    disable_description: 0,
                    force_private: 0,
                    image: null
                }
            },
            {
                objectKey: {
                    id: 15700,
                    name: "Compliment",
                    has_custom_fields: 0,
                    category_id: 605,
                    disable_title: 0,
                    disable_description: 0,
                    force_private: 0,
                    image: null
                }
            },
            {
                objectKey: {
                    id: 17574,
                    name: "Custom Fields, all of them",
                    has_custom_fields: 1,
                    disable_title: 0,
                    disable_description: 0,
                    force_private: 0,
                    image: null,
                    custom_fields: [
                        {
                            custom_field: {
                                id: "1663",
                                name: "I'm a text input",
                                description: "I'm a text input description",
                                type: "text",
                                required: 1,
                                is_public: 1,
                                options: [

                                ]
                            }
                        },
                        {
                            custom_field: {
                                id: "1664",
                                name: "I'm a text input display only",
                                description: "I'm a text input display only description",
                                type: "display",
                                required: 0,
                                is_public: 0,
                                options: [

                                ]
                            }
                        },
                        {
                            custom_field: {
                                id: "1665",
                                name: "I'm a checkbox",
                                description: "I'm a checkbox description",
                                type: "checkbox",
                                required: 0,
                                is_public: 1,
                                options: [

                                ]
                            }
                        },
                        {
                            custom_field: {
                                id: "1666",
                                name: "I'm a single select",
                                description: "I'm a single select description",
                                type: "singleselect",
                                required: 1,
                                is_public: 0,
                                options: [
                                    {
                                        option: {
                                            id: "3751",
                                            name: "A 123 !@@#",
                                            description: "A 123 !@@# description"
                                        }
                                    },
                                    {
                                        option: {
                                            id: "3752",
                                            name: "B ",
                                            description: "B description"
                                        }
                                    },
                                    {
                                        option: {
                                            id: "3753",
                                            name: "C",
                                            description: "C description"
                                        }
                                    },
                                    {
                                        option: {
                                            id: "3754",
                                            name: " D",
                                            description: "D description"
                                        }
                                    }
                                ]
                            }
                        },

                    }
                ],
                s_types: [

                ],
                categories: [
                    {
                        category: {
                            id: 618,
                            client: 1064,
                            name: "Abc",
                            gov_creator: 1841,
                            description: "",
                            parent: 607,
                            date_created: 1368137256,
                            image: null
                        }
                    },
                    {
                        category: {
                            id: 602,
                            client: 1064,
                            name: "Animal Control",
                            gov_creator: 2275,
                            description: "",
                            parent: null,
                            date_created: 1367878768,
                            image: null
                        }
                    },

                }
            ],
            assets: [

            ],
            benchmark: 0.36078095436096
        },
        status: {
            type: "success",
            message: "Success",
            code: 200,
            code_message: "Ok"
        }
    }
}

The real meat is in the request_types key, the second one, which is a JSONArray. Each index contains an object, each object can contain a Custom Fields key which is a json array as well, which in some cases can contain an options json array.

I have models for all of these, for a different parsing paradigm, but not for GSON. I will need to use GSON now because of memory limitations

4

1 回答 1

1

您将需要让我们说A其中包含一个类实例的类B

public class A {
   private B response;
}

那么你将需要类B有1个类实例C

public class B {
   private C request_types;
}

然后C将包含int c_id一个类的数组D和每个其他数组的类。然后类将包含一个名为D的类的单个对象。类将包含...下的所有字段EobjectKeyEobjectKey

依此类推……你说得对,JSON 太复杂了。

于 2013-08-30T02:44:37.080 回答