Skip to content

Instantly share code, notes, and snippets.

@viperwarp
Created October 19, 2011 23:29
Show Gist options
  • Save viperwarp/1299990 to your computer and use it in GitHub Desktop.
Save viperwarp/1299990 to your computer and use it in GitHub Desktop.
Loads a JSON object from a file
public JSONObject getJsonFromUri(String url) throws JSONException, IOException {
URLConnection conn = null;
DataInputStream data = null;
String line;
StringBuffer buf = new StringBuffer();
conn = new URL(url).openConnection();
conn.connect();
data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
while ((line = data.readLine()) != null) {
buf.append(line + "\n");
}
data.close();
return new JSONObject(buf.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment