java - How to Parse this json object nested in json array -
i using code
private void parsedata(jsonarray array){ log.d(tag, "parsing array"); for(int = 0; i<array.length(); i++) { bookitems bookitem = new bookitems(); jsonobject jsonobject = null; try { jsonobject = array.getjsonobject(i); jsonobject bookchapter = jsonobject.getjsonobject("chapter"); bookitem.setbook_subtitle(bookchapter.getstring("subtitle")); jsonobject chapverses = jsonobject.getjsonobject("verses"); jsonarray versereaders = chapverses.getjsonarray("readers"); jsonobject readersnum = versereaders.getjsonobject("number"); versereadnum = readersnum; } catch (jsonexception w) { w.printstacktrace(); } mbookitemslist.add(bookitem); } }
to parse json.
[ { "chapter": { "subtitle": "something happened in in chapter" }, "verses": { "about": [ { "in verse, lot of things happened yes lot!" } ], "readers": [ { "read": false, "number": "no body has read verse yet" } ], } }, ...]
i getting "subtitle" correctly having didfficulty getting "number".
from line jsonobject readersnum = versereaders.getjsonobject("number");
android studio complaining getjsonobject (int) in jsonarray cannnot applied (java.lang.string)
please, how parse this?
versereaders
jsonarray
, need iterate on (or take first) jsonobject
, string object.
string readersnum = versereaders.getjsonobject(0).getstring("number");
Comments
Post a Comment