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