Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private JSONObject readJsonFromUrl(String url) throws IOException, ParseException {
- InputStream is = new URL(url).openStream();
- try {
- BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
- String jsonText = readAll(rd);
- JSONObject json = (JSONObject) new JSONParser().parse(jsonText);
- return json;
- } finally {
- is.close();
- }
- }
- private String readAll(Reader rd) throws IOException {
- StringBuilder sb = new StringBuilder();
- int cp;
- while ((cp = rd.read()) != -1) {
- sb.append((char) cp);
- }
- return sb.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement