Mental Jetsam

By Peter Finch

Archive for September, 2012

Android JSON WebService Example

Posted by pcfinch on September 27, 2012

The following code, for the Android OS, will make a HTTP request to a JSON webservice at “url” and convert the response into a JSONObject.

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(url) ;
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody = httpClient.execute(request, responseHandler);
JSONObject jsonResponse = new JSONObject(responseBody) ;

Posted in Programming | Leave a Comment »