Java URL Load readURLJSONArray(String urlString)

Here you can find the source of readURLJSONArray(String urlString)

Description

read URLJSON Array

License

Open Source License

Declaration

public static JSONArray readURLJSONArray(String urlString) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.json.JSONArray;
import org.json.JSONException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URL;

public class Main {
    public static JSONArray readURLJSONArray(String urlString) {
        try {//  w  ww . ja v a  2  s . c o  m
            return new JSONArray(readURL(urlString));
        } catch (JSONException e) {
            return null;
        }
    }

    public static String readURL(String urlString) {
        try {
            URL url = new URL(urlString);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuilder sb = new StringBuilder();
            int read;
            char[] chars = new char[1024];
            while ((read = reader.read(chars)) != -1)
                sb.append(chars, 0, read);
            reader.close();
            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}

Related

  1. readURL(URL url)
  2. readURL(URL url)
  3. readURLasString(URL url)
  4. readUrlContent(String address)
  5. readURLContents(String UrlText)
  6. readUrlProperties(URL url)
  7. readUrlStream(String urlString)
  8. readUrlText(final URL url, final String encoding)
  9. readURLText(String urlPath, String encoding)