app/src/main/java/com/example/android/quakereport/QueryUtils.java
/**
     * 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 List<Earthquake> extractFeatureFromJson(String earthquakeJSON) {
        if (TextUtils.isEmpty(earthquakeJSON)) {
            return null;
        }
        List<Earthquake> earthquakes = new ArrayList<>();
        try {
            JSONObject baseJsonResponse = new JSONObject(earthquakeJSON);
            JSONArray earthquakeArray = baseJsonResponse.optJSONArray("features");
            for (int i = 0; i < earthquakeArray.length(); i++) {
                JSONObject currentEarthquake = earthquakeArray.getJSONObject(i);
                JSONObject properties = currentEarthquake.getJSONObject("properties");
                double magnitude = properties.getDouble("mag");
                String location = properties.getString("place");
                long time = properties.getLong("time");
                String url = properties.getString("url");
                Earthquake earthquake = new Earthquake(magnitude, location, time, url);
                earthquakes.add(earthquake);
            }
        } catch (JSONException e) {
            Log.e("QueryUtils", "Problem parsing the earthquake JSON results", e);
        }
        return earthquakes;
    }
private static List < Earthquake > extractFeatureFromJson ( String earthquakeJSON ) { if ( TextUtils . isEmpty ( earthquakeJSON ) ) { return null ; } List < Earthquake > earthquakes = new ArrayList < > ( ) ; try { JSONObject baseJsonResponse = new JSONObject ( earthquakeJSON ) ; JSONArray earthquakeArray = baseJsonResponse . optJSONArray ( "features" ) ; for ( int i = 0 ; i < earthquakeArray . length ( ) ; i ++ ) { JSONObject currentEarthquake = earthquakeArray . getJSONObject ( i ) ; JSONObject properties = currentEarthquake . getJSONObject ( "properties" ) ; double magnitude = properties . getDouble ( "mag" ) ; String location = properties . getString ( "place" ) ; long time = properties . getLong ( "time" ) ; String url = properties . getString ( "url" ) ; Earthquake earthquake = new Earthquake ( magnitude , location , time , url ) ; earthquakes . add ( earthquake ) ; } } catch ( JSONException e ) { Log . e ( "QueryUtils" , "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 JSON response string. 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. // Parse the response given by the SAMPLE_JSON_RESPONSE string and // build up a list of Earthquake objects with the corresponding data. // 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