HttpURLConnection establishes connection with API, and data on the web are accessible with Get method.
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
Edgar API™ provides outlet for company financial data for educational, non commercial use. HttpURLConnection activity ought to be conducted in non-main thread, for it shall cause NetworkException.
AsyncTask methods are comprised of doInBackground() and onPostExecute(). URLConnection is established with .setRequestMethod("GET")
. This program is configured to process Json output from "v2-Core Financials YTD". Upon Connection, InputStreamReader, StringBuffer process data and output as String.
Processed jsonStr is parsed as Json. Return values resulting from actions through doInBackground() gets passed to onPostExecute().
jsonParser constructs Json object from String. JsonObjects, JsonArrays, JsonElements comprise json tree.
JsonParser parser = new JsonParser();
JsonObject o = parser.parse(jsonStr).getAsJsonObjet();
JsonObject result = o.getAsJsonObject("result");
JsonArray rows = result.getAsJsonArray("rows");