use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class JSONUrlReader method readJsonArrayFromUrl.
public static JSONArray readJsonArrayFromUrl(Context context, String url) {
// Log.e("JSON",url);
URL serverUrl = null;
HttpURLConnection urlConnection = null;
try {
serverUrl = new URL(url);
urlConnection = (HttpURLConnection) serverUrl.openConnection();
} catch (Exception e) {
// Log.e("JSON1", "" + e.getMessage());
}
JSONArray json = null;
String useCookie = cookieStore.get(url);
InputStream is = null;
if (useCookie != null) {
urlConnection.setRequestProperty("Cookie", useCookie);
}
try {
urlConnection.setRequestProperty("User-Agent", getUserAgent(context));
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setConnectTimeout(URL_TIMEOUT_MILLIS);
urlConnection.setReadTimeout(URL_TIMEOUT_MILLIS);
urlConnection.setInstanceFollowRedirects(true);
} catch (Exception e) {
// Log.e("readJsonObjectFromUrl().error.msg","2:"+e.getMessage());
}
try {
// urlConnection.conn
urlConnection.connect();
} catch (Exception e) {
cookieStore.remove(url);
// Log.e("readJsonObjectFromUrl().error.msg","3 - connect(): "+e.getMessage());
}
try {
is = urlConnection.getInputStream();
} catch (IOException e) {
// Log.e("JSON4",""+e.getMessage());
}
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
// BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String jsonText = readAll(rd);
// Log.e("GOTJSON",jsonText+"");
json = new JSONArray(jsonText);
} catch (Exception e) {
// Log.e("JSON5",""+e.getMessage());
}
try {
is.close();
} catch (Exception e) {
// Log.e("JSON6",""+e.getMessage());
}
return json;
}
Aggregations