• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps problem in json parsing

Dinakar

Lurker
Apr 18, 2020
1
0
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="
"https:earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&eventtype=earthquake&orderby=time&minmag=6&limit=10"
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);
Log.i(LOG_TAG,"JSON OBJECT ERRIR00");
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);
earthquakes.add(ob1);
}
} 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);
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones