app/src/main/java/com/example/android/quakereport/QueryUtils.java
public static ArrayList<EarthquakeItem> extractEarthquakes(String sampleJSON) {

        // Create an empty ArrayList that we can start adding earthquakes to
        if(sampleJSON.isEmpty())
            return null;
        ArrayList<EarthquakeItem> 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 {
            // TODO: Parse the response given by the SAMPLE_JSON_RESPONSE string and
            // build up a list of Earthquake objects with the corresponding data.

            JSONObject earthquakeJSON = new JSONObject(sampleJSON);
            JSONArray earthquakeItem = earthquakeJSON.getJSONArray("features");
            for(int i = 0 ; i < earthquakeItem.length() ; i++ ){
                JSONObject properties = earthquakeItem.getJSONObject(i)
                        .getJSONObject("properties");
                double magnitude = properties.getDouble("mag");
                String url = properties.getString("url");
                String location = properties.getString("place");
                Date date = new Date();
                date.setTime(properties.getLong("time"));

                earthquakes.add(new EarthquakeItem(magnitude,location,date,url));
            }

        } 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("QueryUtils", "Problem parsing the earthquake JSON results", e);
        }

        // Return the list of earthquakes
        Log.v("List is created","done");
        return earthquakes;
    }
/**
     * Return a list of {@link EarthquakeItem} objects that has been built up from
     * parsing a JSON response.
     */
Return a list of  EarthquakeItem objects that has been built up from
parsing a JSON response.
Return a list of EarthquakeItem objects that has been built up from parsing a JSON response .
public static ArrayList<EarthquakeItem> extractEarthquakes(String sampleJSON) {
        if(sampleJSON.isEmpty())
            return null;
        ArrayList<EarthquakeItem> earthquakes = new ArrayList<>();
        try {
            JSONObject earthquakeJSON = new JSONObject(sampleJSON);
            JSONArray earthquakeItem = earthquakeJSON.getJSONArray("features");
            for(int i = 0 ; i < earthquakeItem.length() ; i++ ){
                JSONObject properties = earthquakeItem.getJSONObject(i)
                        .getJSONObject("properties");
                double magnitude = properties.getDouble("mag");
                String url = properties.getString("url");
                String location = properties.getString("place");
                Date date = new Date();
                date.setTime(properties.getLong("time"));
                earthquakes.add(new EarthquakeItem(magnitude,location,date,url));
            }
        } catch (JSONException e) {
            Log.e("QueryUtils", "Problem parsing the earthquake JSON results", e);
        }
        Log.v("List is created","done");
        return earthquakes;
    }
public static ArrayList < EarthquakeItem > extractEarthquakes ( String sampleJSON ) { if ( sampleJSON . isEmpty ( ) ) return null ; ArrayList < EarthquakeItem > earthquakes = new ArrayList < > ( ) ; try { JSONObject earthquakeJSON = new JSONObject ( sampleJSON ) ; JSONArray earthquakeItem = earthquakeJSON . getJSONArray ( "features" ) ; for ( int i = 0 ; i < earthquakeItem . length ( ) ; i ++ ) { JSONObject properties = earthquakeItem . getJSONObject ( i ) . getJSONObject ( "properties" ) ; double magnitude = properties . getDouble ( "mag" ) ; String url = properties . getString ( "url" ) ; String location = properties . getString ( "place" ) ; Date date = new Date ( ) ; date . setTime ( properties . getLong ( "time" ) ) ; earthquakes . add ( new EarthquakeItem ( magnitude , location , date , url ) ) ; } } catch ( JSONException e ) { Log . e ( "QueryUtils" , "Problem parsing the earthquake JSON results" , e ) ; } Log . v ( "List is created" , "done" ) ; return earthquakes ; }
Return a list of {@link EarthquakeItem} objects that has been built up from
 parsing a JSON response.
Return a list of { @link EarthquakeItem } 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. // TODO: 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