java - Android JSON parsing of multiple JSONObjects inside JSONObject -
i have json string coming server , looks this
{ "categories": { "0": { "term_id": "247", "name": "content curation" }, "1": { "term_id": "50", "name": "content marketing" }, "2": { "term_id": "2", "name": "curation" }, "3": { "term_id": "246", "name": "inbound marketing" }, "4": { "term_id": "47", "name": "marketing" }, "5": { "term_id": "4", "name": "news curation" }, "6": { "term_id": "36", "name": "seo" }, "8": { "term_id": "248", "name": "wordpress content curation" } }
}
my task values of "term_id" , "name" fields. i've used "categories" object current jsonobject using code.
jsonobject jobject = new jsonobject(responcedata); jsonobject categoryobject = jobject.getjsonobject("categories"); jsonarray jarray = new jsonarray("["+categoryobject.tostring().substring(1,categoryobject.tostring().length() - 1) + "]"); for(int i=0;i<jarray.length();i++) { jsonobject jobj = jarray.getjsonobject(i); string term_id=jobj.getstring("term_id"); string name=jobj.getstring("name"); }
and categoryobject looks this
{ "0": { "term_id": "247", "name": "content curation" }, "1": { "term_id": "50", "name": "content marketing" }, "2": { "term_id": "2", "name": "curation" }, "3": { "term_id": "246", "name": "inbound marketing" }, "4": { "term_id": "47", "name": "marketing" }, "5": { "term_id": "4", "name": "news curation" }, "6": { "term_id": "36", "name": "seo" }, "8": { "term_id": "248", "name": "wordpress content curation" }
}
but after don't know how fields. there way jsonobject childs jsonobject?
if have source code or can give me example please share me.
here can retrieve json data, ask specific key , innerkey want, cheers
try { string jsonstring="";//your json string here jsonobject jobject= new jsonobject(jsonstring).getjsonobject("categories"); iterator<string> keys = jobject.keys(); while( keys.hasnext() ) { string key = keys.next(); log.v("**********", "**********"); log.v("category key", key); jsonobject innerjobject = jobject.getjsonobject(key); iterator<string> innerkeys = innerjobject.keys(); while( innerkeys.hasnext() ) { string innerkkey = keys.next(); string value = innerjobject.getstring(innerkkey); log.v("key = "+key, "value = "+value); } } } catch (jsonexception e) { e.printstacktrace(); }
Comments
Post a Comment