TODO State Processing 500 200
int res = 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 JSON data and do the processing
* */
HttpResponse HttpResponse = Httpclient.execute (HttpPost);
StringBuilder builder = new StringBuilder ();
BufferedReader bufferedReader2 = new BufferedReader (
New InputStreamReader (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 = new Jsonobject (builder.tostring ())
. Getjsonobject ("Userbean");
UID = jsonobject.getstring ("UID");
ShowName = jsonobject.getstring ("ShowName");
Avtar = jsonobject.getstring ("Avtar");
State = jsonobject.getstring ("state");
With array form:
The data format returned by the server side is:
TODO State Processing 500 200
int res = 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 JSON data and do the processing
* */
HttpResponse HttpResponse = Httpclient.execute (HttpPost);
StringBuilder builder = new StringBuilder ();
BufferedReader bufferedReader2 = new BufferedReader (
New InputStreamReader (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 from the server.
*/
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);
}
To sum up, the ordinary form of simply using Jsonobject, with array form needs to use Jsonarray to turn it into a list.
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.