Issue:
I'm getting data from web-services in JSON format.I am trying to parse "quote" an "Author" but,i am unable to do it.
Here is the data:
{
"success": {
"total": 1
},
"contents": {
"quotes": [
{
"quote": "You are very powerful, provided you know how powerful you are.",
"author": "Yogi Bhajan",
"category": "inspire",
"date": "2018-02-15",
"title": "Inspiring Quote of the day"
}
],
"copyright": "2017-19 theysaidso.com"
}
}
My Java code is :
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("quotes");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject getQuote = jsonArray.getJSONObject(i);
String quoteOfTheDay = getQuote.getString("quote");
String author = getQuote.getString("author");
quotesView.append(quoteOfTheDay + author + "\n\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
I'm certain that logic for parsing in Java class is incorrect.
Which logic should I use to correct this?