app/src/main/java/com/example/android/quakereport/QueryUtils.java
private static ArrayList<Earthquake> extractFeatureFromJson(String earthquakeJSON)
    {

        // Create an empty ArrayList that we can start adding earthquakes to
        ArrayList<Earthquake> earthquakes = new ArrayList<>();

        // Try to parse the SAMPLE_JSON_RESPONSE. If there's a problem with the way the JSON
        // is formatted, a JSONException exception object will be thrown.
        // Catch the exception so the app doesn't crash, and print the error message to the logs.
        try
        {
            //Create json object
            JSONObject root = new JSONObject(earthquakeJSON);

            //abstract json array
            JSONArray featuresArray = root.optJSONArray("features");

            //iterate through the array of all earthquakes
            for(int i = 0 ; i < featuresArray.length(); i++)
            {
                //Create object of current earthquake
                JSONObject currentEarthquake = featuresArray.getJSONObject(i);

                //abstract properties object of current earthquake
                JSONObject propertiesObject = currentEarthquake.getJSONObject("properties");

                //extract mag for magnitude
                double magnitude = propertiesObject.getDouble("mag");

                //extract place for location
                String place = propertiesObject.getString("place");

                //extract time for time in unix format
                long millisecondsTime = propertiesObject.getLong("time");

                String url = propertiesObject.getString("url");

                //Create earthquake java object and add items
                Earthquake queryItem = new Earthquake(magnitude, place, millisecondsTime, url);
                //add earthquake java object to ArrayList
                earthquakes.add(queryItem);
            }

        }
        catch (JSONException e)
        {
            // If an error is thrown when executing any of the above statements in the "try" block,
            // catch the exception here, so the app doesn't crash. Print a log message
            // with the message from the exception.
            Log.e(LOG_TAG, "Problem parsing the earthquake JSON results", e);
        }

        // Return the list of earthquakes
        return earthquakes;
    }
/**
     * Return a list of {@link Earthquake} objects that has been built up from
     * parsing a JSON response.
     */
Return a list of  Earthquake objects that has been built up from
parsing a JSON response.
Return a list of Earthquake objects that has been built up from parsing a JSON response .
private static ArrayList<Earthquake> extractFeatureFromJson(String earthquakeJSON)
    {
        ArrayList<Earthquake> earthquakes = new ArrayList<>();
        try
        {
            JSONObject root = new JSONObject(earthquakeJSON);
            JSONArray featuresArray = root.optJSONArray("features");
            for(int i = 0 ; i < featuresArray.length(); i++)
            {
                JSONObject currentEarthquake = featuresArray.getJSONObject(i);
                JSONObject propertiesObject = currentEarthquake.getJSONObject("properties");
                double magnitude = propertiesObject.getDouble("mag");
                String place = propertiesObject.getString("place");
                long millisecondsTime = propertiesObject.getLong("time");
                String url = propertiesObject.getString("url");
                Earthquake queryItem = new Earthquake(magnitude, place, millisecondsTime, url);
                earthquakes.add(queryItem);
            }
        }
        catch (JSONException e)
        {
            Log.e(LOG_TAG, "Problem parsing the earthquake JSON results", e);
        }
        return earthquakes;
    }
private static ArrayList < Earthquake > extractFeatureFromJson ( String earthquakeJSON ) { ArrayList < Earthquake > earthquakes = new ArrayList < > ( ) ; try { JSONObject root = new JSONObject ( earthquakeJSON ) ; JSONArray featuresArray = root . optJSONArray ( "features" ) ; for ( int i = 0 ; i < featuresArray . length ( ) ; i ++ ) { JSONObject currentEarthquake = featuresArray . getJSONObject ( i ) ; JSONObject propertiesObject = currentEarthquake . getJSONObject ( "properties" ) ; double magnitude = propertiesObject . getDouble ( "mag" ) ; String place = propertiesObject . getString ( "place" ) ; long millisecondsTime = propertiesObject . getLong ( "time" ) ; String url = propertiesObject . getString ( "url" ) ; Earthquake queryItem = new Earthquake ( magnitude , place , millisecondsTime , url ) ; earthquakes . add ( queryItem ) ; } } catch ( JSONException e ) { Log . e ( LOG_TAG , "Problem parsing the earthquake JSON results" , e ) ; } return earthquakes ; }
Return a list of {@link Earthquake} objects that has been built up from
 parsing a JSON response.
Return a list of { @link Earthquake } objects that has been built up from parsing a JSON response .
// Create an empty ArrayList that we can start adding earthquakes to // Try to parse the SAMPLE_JSON_RESPONSE. If there's a problem with the way the JSON // is formatted, a JSONException exception object will be thrown. // Catch the exception so the app doesn't crash, and print the error message to the logs. //Create json object //abstract json array //iterate through the array of all earthquakes //Create object of current earthquake //abstract properties object of current earthquake //extract mag for magnitude //extract place for location //extract time for time in unix format //Create earthquake java object and add items //add earthquake java object to ArrayList // If an error is thrown when executing any of the above statements in the "try" block, // catch the exception here, so the app doesn't crash. Print a log message // with the message from the exception. // Return the list of earthquakes