Skip to content

Instantly share code, notes, and snippets.

@adam-davis
Created January 24, 2012 23:18
Show Gist options
  • Save adam-davis/1673421 to your computer and use it in GitHub Desktop.
Save adam-davis/1673421 to your computer and use it in GitHub Desktop.
A snippet of Java code for retrieving JSON results from PHP
public static JSONArray HttpGetJSON(String url) throws ClientProtocolException, IOException
{
JSONArray jsonArrayResults = null;
HttpClient client = new DefaultHttpClient();
HttpGet loginPost = new HttpGet(url);
HttpResponse response=client.execute(loginPost);
String phpJsonResults= EntityUtils.toString(response.getEntity());
try {
jsonArrayResults = new JSONArray(phpJsonResults);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonArrayResults;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment