Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Created November 24, 2015 20:39
Show Gist options
  • Save sax1johno/fcf89415ad17d05990da to your computer and use it in GitHub Desktop.
Save sax1johno/fcf89415ad17d05990da to your computer and use it in GitHub Desktop.
URL apod = new URL(APOD_URL);
HttpURLConnection urlConnection = (HttpURLConnection) apod.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String jsonContent = br.readLine();
apodData = new JSONObject(jsonContent);
@sax1johno
Copy link
Author

// You can also do the following if there's more than one line of JSON
StringBuilder jsonBuilder = new StringBuilder();
String line;
while (line = br.readLine() != null) {
jsonBuilder.append(line);
}
String jsonContent = jsonBuilder.toString();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment