Created
October 19, 2011 23:29
-
-
Save viperwarp/1299990 to your computer and use it in GitHub Desktop.
Loads a JSON object from a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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