复杂的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> result;
    private int error_code;
    private String reason;
    public void setResult(List<Result> result) {
        this.result = result;
    }
    public List<Result> 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解析,但是返回的是一个对象,想要转换成自己想要的实体类还没搞懂。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值