首页 > 移动平台 > 详细

Android Gson解析复杂Json

时间:2014-07-22 22:35:24      阅读:392      评论:0      收藏:0      [点我收藏+]

JSON原数据

{"total":1,"rows":[{"ID":1,"Title":"台州初级中学招收初一年级体育特长生的通告","Content":"",
"Type":"01","ReceiveUserName":"蔡婧怡","IsRead":0,"SendDate":"2014-07-18 15:21:40","SendUserName":"网站开发员"}]}

 

自定义model存放解析后的结果

public class MessageCenter {
    private int ID;
    private String Title;
    private String Content;
    private String Type;
    private String ReceiveUserName;
    private int IsRead;
    private String SendDate;
    private String SendUserName;

    public int getID() {
        return ID;
    }
    public void setID(int iD) {
        ID = iD;
    }
    public String getTitle() {
        return Title;
    }
    public void setTitle(String title) {
        Title = title;
    }
    public String getContent() {
        return Content;
    }
    public void setContent(String content) {
        Content = content;
    }
    public String getType() {
        return Type;
    }
    public void setType(String type) {
        Type = type;
    }
    public String getReceiveUserName() {
        return ReceiveUserName;
    }
    public void setReceiveUserName(String receiveUserName) {
        ReceiveUserName = receiveUserName;
    }

    public int getIsRead() {
        return IsRead;
    }
    public void setIsRead(int isRead) {
        IsRead = isRead;
    }
    public String getSendDate() {
        return SendDate;
    }
    public void setSendDate(String sendDate) {
        SendDate = sendDate;
    }
    public String getSendUserName() {
        return SendUserName;
    }
    public void setSendUserName(String sendUserName) {
        SendUserName = sendUserName;
    }
}

 

import java.util.List;

public class MessageCenterJsonBean {
    private int total;
    private List<MessageCenter> rows;
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    public List<MessageCenter> getRows() {
        return rows;
    }
    public void setRows(List<MessageCenter> rows) {
        this.rows = rows;
    }
}

 

解析JSON,resultString为JSON原数据

public static void main(String[] args) {
    Gson gson = new Gson();
    try {        
        MessageCenterJsonBean mcj= new GsonBuilder().create().fromJson(resultString, MessageCenterJsonBean.class);
        System.out.println(mcj.getTotal());
    } catch (Exception e) {
    }
}

Android Gson解析复杂Json,布布扣,bubuko.com

Android Gson解析复杂Json

原文:http://www.cnblogs.com/chenjianxiang/p/3860907.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!