Android Gson解析複雜Json

來源:互聯網
上載者:User

標籤:android   style   blog   java   color   資料   

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) {    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.