Tuesday, August 4, 2015

[Android] Calling Web Resource using JSOUP

Below is a sample code to call web resource using JSOUP API which can be found from this link - http://jsoup.org.


import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public static JSONObject getJSONMessage(){

 Document doc;
 JSONObject jObject;
 try {
  doc = Jsoup.connect("http://dummy.com/MyServlet").ignoreContentType(true).get();
  jObject = new JSONObject(doc.text());
 } catch (IOException e) {
   e.printStackTrace();
 }catch(org.json.JSONException e){
   e.printStackTrace();
 }
 return jObject;
}

No comments:

Post a Comment