java - How to Extract JSON value outside of Array -
at moment can loop through json array ''pos" , store variables within array list.
what i'm trying do:
how can parse tour & date outside "pos" array?
i store values in "tour" & "date" 2 separate string variables.
my understanding: json.getjsonarray() can't used in case, json.getjsonarray(tag_messages); pulls in "pos" array data.
json structure:
{ "pos": [ { "pos": "", "person": "", "thur": "", "score": "", "round": "" }, { "pos": "2", "person": "john", "thur": "", "score": "16", "round": "3" }, { "pos": "3", "person": "peter lynch", "thur": "", "score": "5", "round": "2" } ], "tour": "camping", "date": "thursday jul 23 - sunday jul 26, 2015" }
code parse json pos array:
// json nodes private static final string tag_messages = "pos"; private static final string tag_id = "pos"; private static final string tag_from = "person"; private static final string tag_email = "thur"; private static final string tag_subject = "round"; private static final string tag_date = "score"; // these outside of array pos private static final string tag_tour = "tour"; private static final string tag_tourdate = "date"; try { inbox = json.getjsonarray(tag_messages); inbox.tostring(); // looping through messages (int = 0; < inbox.length(); i++) { jsonobject c = inbox.getjsonobject(i); // storing each json item in variable string id = c.getstring(tag_id); // creating new hashmap hashmap<string, string> map = new hashmap<string, string>(); // adding each child node hashmap key => value map.put(tag_id, id); map.put(tag_from, from); map.put(tag_email, mailer); map.put(tag_date, date); map.put(tag_subject, subject); // adding hashlist arraylist inboxlist.add(map);
as can jsonarray
json , can string
too.
something :
json.getstring("tour"); json.getstring("date");
Comments
Post a Comment