1. Are you ready for the Galaxy S20? Here is everything we know so far!

problem in json parsing

Discussion in 'Android Development' started by Dinakar, Apr 18, 2020.

  1. Dinakar

    Dinakar Lurker
    Thread Starter

    here i am trying to parse my json response but i 'm getting a json exception that string cannot be converted to json object . api="
    in the given code the lred colored line gives me the error..
    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 ins = new JSONObject(api);
    JSONArray Features = ins.getJSONArray("features");
    for (int i = 0; i < ins.length(); i++) {
    JSONObject ob = Features.getJSONObject(i);
    JSONObject props = ob.getJSONObject("properties");
    Double magnitude = props.getDouble("mag");
    String location = props.getString("place");
    String link = props.getString("url");
    Long time = props.getLong("time");
    Earth ob1 = new Earth(magnitude, location, time, link);
    } 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);

    1. Download the Forums for Android™ app!



Share This Page