gson parse始终为null,列表中包含列表

时间:2017-06-12 06:38:03

标签: android json gson

我有一些阵列,但不知何故他们没有得到正确的解析......

我第一次使用gson所以不知道......(在线阅读所有线索,让我相信我的结构是正确的......

ResponseResult.ResponseCode内的信息都正确匹配。但ResponseData不是。

我做了init:

ResponseResult responseResult = gson.fromJson(new String(response),ResponseResult.class);

我的班级:

public class ResponseResult
{
    public ResponseCode responseCode;
    public ResponseData responseData;
}

public class ResponseCode
{
    public int errorCode;
    public String errorMessage;
}

public class ResponseData
{
    // support
    public int support_id;

    // faq
    public List<ResponseFaqSection> faq;

}

public class ResponseFaqSection
{
    public int section_id;
    public String section_language;
    public int section_order;
    public String section_title;
    public String section_subtitle;
    public String section_image;
    public  String section_created;
    public  String section_updated;
    public int section_published;
    public int section_deleted;
    public List<ResponseFaqItem> items;
}

public class ResponseFaqItem
{
    public int faq_id;
    public String faq_language;
    public int section_id;
    public int faq_order;
    public String faq_title;
    public String faq_subtitle;
    public String faq_message;
    public String faq_image;
    public String faq_created;
    public String faq_updated;
    public  int faq_published;
    public int faq_deleted;
}

和json&#34;

{
"responseCode":{
"errorCode":0,
"errorMessage":"api_error_ok"
},
"responseData":{
"faq":[
{
"section_id":"3",
"section_language":"english",
"section_order":"0",
"section_title":"General",
"section_subtitle":"General Information",
"section_image":"",
"section_created":"2017-04-27 13:55:48",
"section_updated":"2017-04-27 13:55:48",
"section_published":"1",
"section_deleted":"0",
"items":[
{
"faq_id":"1",
"section_id":"3",
"faq_language":"english",
"faq_order":"0",
"faq_title":"Can I contact Jiffy?",
"faq_subtitle":"Can I contact Jiffy?",
"faq_message":"Yes, you can contact jiffy through the contact form inside the application.",
"faq_image":"",
"faq_created":"2017-04-27 13:57:34",
"faq_updated":"0000-00-00 00:00:00",
"faq_published":"1",
"faq_deleted":"0"
}
]
},
{
"section_id":"4",
"section_language":"english",
"section_order":"1",
"section_title":"Security",
"section_subtitle":"Questions about security",
"section_image":"",
"section_created":"2017-04-27 13:55:48",
"section_updated":"2017-04-27 13:55:48",
"section_published":"1",
"section_deleted":"0",
"items":[
{
"faq_id":"2",
"section_id":"4",
"faq_language":"english",
"faq_order":"0",
"faq_title":"Is my line secure?",
"faq_subtitle":"Is my line secure?",
"faq_message":"Yes, Jiffy uses a 256-bit SSL Certificate to secure your connection.",
"faq_image":"",
"faq_created":"2017-04-27 13:57:34",
"faq_updated":"0000-00-00 00:00:00",
"faq_published":"1",
"faq_deleted":"0"
}
]
}
]
}
}

在使用代码后,问题出在&#34;子列表&#34;叫&#34;项目&#34;

public class ResponseFaqSection
    {
        public int section_id;
        public String section_language;
        public int section_order;
        public String section_title;
        public String section_subtitle;
        public String section_image;
        public  String section_created;
        public  String section_updated;
        public int section_published;
        public int section_deleted;
        public List<ResponseFaqItem> items; <--- FAILS HERE
    }

1 个答案:

答案 0 :(得分:0)

这是你的问题专栏(在Faqsection中):

 List<faq> items[];

您告诉它输入是一个数组列表。它不可能都是。