Mental Jetsam

By Peter Finch

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) ;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: