复杂的Json格式解析及报错

从阿凡达获取的API示例:

{
  "error_code": 0,
  "reason": "Succes",
  "result": [
    {
      "ctime": "2015-10-21 12:56",
      "title": "李宝荣任国管局局长、党组书记 焦焕成到龄卸任",
      "description": "10月20日,国管局召开领导干部会议,宣布中共中央关于国管局主要领导调整的决定,李宝荣同志任国管局局长、党组书记,焦焕成同志已到任职年龄,不再担任国管局局长、党组书记职务。焦焕成同志表示,衷心拥护中央的决定。在国管局工作的30多年,是人生经",
      "picUrl": "http://s.cimg.163.com/cnews/2015/10/21/2015102111454712c3a_550.jpg.119x83.jpg",
      "url": "http://news.163.com/15/1021/12/B6F0FNPP00014AED.html#f=dlist"
    },
    {
      "ctime": "2015-10-21 11:35",
      "title": "朱立伦暂定11月访美,台媒称接待规格或高于蔡英文",
      "description": "国民党2016参选人朱立伦10月21日表示,访美行程暂时会订在11月中上旬,协调好后再宣布。对于是否还会有其它出访计划,朱立伦说,比较困难,可能会派代表或与对方在台湾的代表接触,包括日本、东南亚、欧美国家等,让他们了解国民党的政策。据透露,",
      "picUrl": "http://s.cimg.163.com/cnews/2015/10/21/20151021105327df31f_550.jpg.119x83.jpg",
      "url": "http://news.163.com/15/1021/11/B6ERQ2DM00014AED.html#f=dlist"
    },
    ......
  ]
}

通过在线json解析出两个实体类:

JsonRootBean

public class JsonRootBean {

    private List result;
    private int error_code;
    private String reason;
    public void setResult(List result) {
        this.result = result;
    }
    public List getResult() {
        return result;
    }

    public void setError_code(int error_code) {
        this.error_code = error_code;
    }
    public int getError_code() {
        return error_code;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }
    public String getReason() {
        return reason;
    }

}

Result

package com.zjc.verticalfragment.model;


public class Result {

    private String title;
    private String content;
    private String img_width;
    private String full_title;
    private String pdate;
    private String src;
    private String img_length;
    private String img;
    private String url;
    private String pdate_src;
    public void setTitle(String title) {
        this.title = title;
    }
    public String getTitle() {
        return title;
    }

    public void setContent(String content) {
        this.content = content;
    }
    public String getContent() {
        return content;
    }

    public void setImg_width(String img_width) {
        this.img_width = img_width;
    }
    public String getImg_width() {
        return img_width;
    }

    public void setFull_title(String full_title) {
        this.full_title = full_title;
    }
    public String getFull_title() {
        return full_title;
    }

    public void setPdate(String pdate) {
        this.pdate = pdate;
    }
    public String getPdate() {
        return pdate;
    }

    public void setSrc(String src) {
        this.src = src;
    }
    public String getSrc() {
        return src;
    }

    public void setImg_length(String img_length) {
        this.img_length = img_length;
    }
    public String getImg_length() {
        return img_length;
    }

    public void setImg(String img) {
        this.img = img;
    }
    public String getImg() {
        return img;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    public String getUrl() {
        return url;
    }

    public void setPdate_src(String pdate_src) {
        this.pdate_src = pdate_src;
    }
    public String getPdate_src() {
        return pdate_src;
    }

}
这是纠错之后的实体类,之前在线转换时pdate_src默认为Date类型,这里我直接修改为String类型,就得到了解决。我用的Gson解析,但是返回的是一个对象,想要转换成自己想要的实体类还没搞懂。。。

你可能感兴趣的:(errors,安卓开发)