Android parsing JSON data format (RPM)

Source: Internet
Author: User

JSON data Format parsing I myself divided into two kinds;

One is ordinary, and one is an array form;




In the ordinary form:
The JSON data format returned by the server side is as follows:

{"Userbean": {"Uid": "100196", "ShowName": "\u75af\u72c2\u7684\u7334\u5b50", "Avtar":null, "state": 1}}

The analysis code is as follows:

//TODO Status Processing                intres = 0; Res=Httpclient.execute (HttpPost). Getstatusline (). Getstatuscode (); if(res = = 200) {                     /** When the return code is 200, do the processing * Get the server side to return the JSON data, and do processing **/HttpResponse HttpResponse=Httpclient.execute (HttpPost); StringBuilder Builder=NewStringBuilder (); BufferedReader BufferedReader2=NewBufferedReader (NewInputStreamReader (Httpresponse.getentity (). GetContent ())); String str2= "";  for(String s = bufferedreader2.readline (); s! =NULL; s =bufferedReader2. ReadLine ())                     {Builder.append (s); } log.i ("Cat", ">>>>>>" +builder.tostring ()); Jsonobject Jsonobject=NewJsonobject (Builder.tostring ()). Getjsonobject ("Userbean");                 String Uid;                 String ShowName;                 String Avtar;                 String State; Uid= Jsonobject.getstring ("Uid"); ShowName= Jsonobject.getstring ("ShowName"); Avtar= Jsonobject.getstring ("Avtar"); State= Jsonobject.getstring ("state");

With the form of an array:
The data format returned by the server side is:

{"Calendar":     {"calendarlist":             [             {"calendar_id": "1705", "title": "(\U4EB2\U5B50) DDSSD "," Category_name ":" \u9ed8\u8ba4\u5206\u7c7b "," Showtime ":" 1288927800 "," Endshowtime ":" 1288931400 "," AllDay ": false },             {"calendar_id": "1706", "title": "(\u65c5\u884c)", "Category_name": "\u9ed8\u8ba4\u5206\u7c7b", " Showtime ":" 1288933200 "," Endshowtime ":" 1288936800 "," AllDay ":false}             ]     }}

The analysis code is as follows:

//TODO Status Processing                intres = 0; Res=Httpclient.execute (HttpPost). Getstatusline (). Getstatuscode (); if(res = = 200) {                     /** When the return code is 200, do the processing * Get the server side to return the JSON data, and do processing **/HttpResponse HttpResponse=Httpclient.execute (HttpPost); StringBuilder Builder=NewStringBuilder (); BufferedReader BufferedReader2=NewBufferedReader (NewInputStreamReader (Httpresponse.getentity (). GetContent ())); String str2= "";  for(String s = bufferedreader2.readline (); s! =NULL; s =bufferedReader2. ReadLine ())                     {Builder.append (s); } log.i ("Cat", ">>>>>>" +builder.tostring ()); /*** Here you need to analyze the JSON format data of the server callback.*/Jsonobject Jsonobject=NewJsonobject (Builder.tostring ()). Getjsonobject ("Calendar"); Jsonarray Jsonarray= Jsonobject.getjsonarray ("Calendarlist");  for(intI=0;i<jsonarray.length (); i++) {Jsonobject jsonObject2=(jsonobject) jsonarray.opt (i); Calendarinfo Calendarinfo=NewCalendarinfo (); CALENDARINFO.SETCALENDAR_ID (Jsonobject2.getstring ("CALENDAR_ID")); Calendarinfo.settitle (Jsonobject2.getstring ("Title")); Calendarinfo.setcategory_name (Jsonobject2.getstring ("Category_name")); Calendarinfo.setshowtime (Jsonobject2.getstring ("Showtime")); Calendarinfo.setendtime (Jsonobject2.getstring ("Endshowtime")); Calendarinfo.setallday (Jsonobject2.getboolean ("AllDay"));                     Calendarinfos.add (Calendarinfo); }

In summary, the normal form simply uses the Jsonobject, with the array form needed to use Jsonarray to turn it into a list.

Android parsing JSON data format (RPM)

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.