JSON parsing of Android development

Source: Internet
Author: User

1. Get JSON return string from Web page
public class Readnet extends Asynctask<url, Integer, string> {

@Override
protected void OnPreExecute () {
Super.onpreexecute ();
}
@Override
Protected String doinbackground (URL ... params) {
StringBuffer sb = new StringBuffer ();
try {
HttpURLConnection connection = (httpurlconnection) params[0].openconnection ();
InputStream is = Connection.getinputstream ();
BufferedReader reader = new BufferedReader (new InputStreamReader (IS, "UTF-8"));
String ReadLine;
while ((ReadLine = Reader.readline ()) = null) {
Sb.append (ReadLine);
Sb.append ("\ n");
}
} catch (IOException e) {
E.printstacktrace ();
}
return sb.tostring ();//Get JSON
}

@Override
protected void OnPostExecute (String s) {

Document doc = Jsoup.parse (s);
Showarticle.settext (Doc.tostring ());
Super.onpostexecute (s);
}
}
2. Parsing JSON strings with Jsonobject class and Jsonarray class
Jsonobject jsonobject = new Jsonobject (jsonstring);//{}
Jsonarray Jsonarray = new Jsonarray (jsonstring);//[{1},{2}]
Jsonobject jsonobject = jsonarray.optjsonobject (1);
The parsing can be placed in the list.

JSON parsing of Android development

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.