Data transfer and JSON parsing between Android and server

Source: Internet
Author: User

JSON Common Types Introduction

The object-oriented data types commonly used in daily life are "objects" and "arrays" that face collections.

Objects commonly handle single objects, and arrays are used to process collection data.

How Android handles two types of data

1, Object handling

                    int res = 0;                    res = Httpclient.execute (httppost). Getstatusline (). Getstatuscode (); if (res = = 200) {/* * When return code is 200, do processing * Get server side return JSON                        Data, and do the processing * */HttpResponse HttpResponse = Httpclient.execute (HttpPost);                        StringBuilder builder = new StringBuilder (); BufferedReader bufferedReader2 = new BufferedReader (New InputStreamReader (httpresponse.get                        Entity (). getcontent ());                        String str2 = "";                            for (String s = bufferedreader2.readline (); s! = null; s = bufferedReader2. ReadLine ()) {                        Builder.append (s);         } jsonobject jsonobject = new Jsonobject (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");
2, array processing

                    int res = 0;                    res = Httpclient.execute (httppost). Getstatusline (). Getstatuscode (); if (res = = 200) {/* * When return code is 200, do processing * Get server side return JSON                        Data, and do the processing * */HttpResponse HttpResponse = Httpclient.execute (HttpPost);                        StringBuilder builder = new StringBuilder (); BufferedReader bufferedReader2 = new BufferedReader (New InputStreamReader (httpresponse.get                        Entity (). getcontent ());                        String str2 = "";                            for (String s = bufferedreader2.readline (); s! = null; s = bufferedReader2. ReadLine ()) {                        Builder.append (s);                        }/** * Here you need to analyze the JSON format data for the server callbacks, */ JsOnobject jsonobject = new Jsonobject (builder.tostring ()). Getjsonobject ("Calendar");                        Jsonarray Jsonarray = Jsonobject.getjsonarray ("Calendarlist"); for (int i=0;i<jsonarray.length (); i++) {Jsonobject jsonObject2 = (jsonobject) jsonarray.opt (i)                            ;                            Calendarinfo calendarinfo = new Calendarinfo ();                            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); }

Summarize

Android.jar file analysis As a Java project, usually introduces the tool class to be used, that is, the jar package, in Android development, most of the development of the toolkit is encapsulated in a file called Android.jar. If we expand in eclipse, we can see the packages in J2se, the packages in the Apache project, and the package files of Android itself. Here we simply browse the Android package file: Android.app: Provides a high-level program model, provides a basic operating environment Android.content: Contains various classes that access and publish data on the device android.database : Browse and manipulate database Android.graphics through content providers: the underlying graphics library, which contains the canvas, color filters, dots, rectangles, can draw them directly onto the screen. Android.location: Classes for targeting and related services Android.media : Provides some classes to manage a variety of audio and video media interfaces Android.net: Provides a class to help network access, exceeding the usual java.net.* interface Android.os: Provides system services, message transmission, IPC mechanisms Android.opengl : Provides OpenGL tools Android.provider: Provides class access to Android content provider Android.telephony: Provides API interaction related to making calls Android.view : Provides a basic UI interface framework Android.util: Methods involving tools, such as the operation of a time-date Android.webkit: Default browser Action interface Android.widget: contains various UI Elements (mostly visible) are used in the application's screen


Data transfer and JSON parsing between Android and server

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.