Android Gson Parsing Complex JSON

Source: Internet
Author: User

JSON raw Data

{"Total": 1, "Rows": [{"ID": 1, "Title": "The first year of Taizhou Junior middle School recruits the first grade sports specialty notice", "Content": "",
"Type": "Receiveusername", "Cai", "Isread": 0, "senddate": "2014-07-18 15:21:40", "Sendusername": "Web Developer"}]}

Custom Model Store parsed results

 Public classMessagecenter {Private intID; PrivateString Title; PrivateString Content; PrivateString Type; PrivateString Receiveusername; Private intIsread; PrivateString senddate; PrivateString Sendusername;  Public intGetID () {returnID; }     Public voidSetID (intID) {ID=ID; }     PublicString GetTitle () {returnTitle; }     Public voidSettitle (String title) {Title=title; }     PublicString getcontent () {returnContent; }     Public voidsetcontent (String content) {content=content; }     PublicString GetType () {returnType; }     Public voidsetType (String type) {type=type; }     PublicString Getreceiveusername () {returnReceiveusername; }     Public voidsetreceiveusername (String receiveusername) {receiveusername=Receiveusername; }     Public intGetisread () {returnIsread; }     Public voidSetisread (intisread) {Isread=Isread; }     PublicString getsenddate () {returnsenddate; }     Public voidsetsenddate (String senddate) {senddate=senddate; }     PublicString Getsendusername () {returnSendusername; }     Public voidsetsendusername (String sendusername) {sendusername=Sendusername; }}

Importjava.util.List; Public classMessagecenterjsonbean {Private intTotal ; PrivateList<messagecenter>rows;  Public intgettotal () {returnTotal ; }     Public voidSettotal (intTotal ) {         This. Total =Total ; }     PublicList<messagecenter>getRows () {returnrows; }     Public voidSetrows (list<messagecenter>rows) {         This. rows =rows; }}

Parsing json,resultstring as JSON raw data

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.