create a class representing the fields of your json. and in your web service pass this in the method parameter. and run this method in your backthread (asyncTask)
public static String postAPIResponse(String url, String data) { HttpURLConnection con = null; InputStream inputStream; StringBuffer responses = null; try { URL urlObject = new URL(url); con = (HttpURLConnection) (urlObject.openConnection()); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); con.setRequestProperty("Content-Length", Integer.toString(data.getBytes().length)); con.setRequestProperty("Content-Language", "en-US"); if (Cookie.getCookie() != null) con.addRequestProperty("Cookie", Cookie.getCookie()); con.setUseCaches(false); con.setDoInput(true); con.setDoOutput(true);
where the data is a json new object string JsonObject.accumulate () ... etc. to map to your service object
Pramod mishra
source share