Android : How do I get the key for each object in a dynamic JSON array?

on Wednesday, July 9, 2014


How do I parse this object and get the name (key) for each person?


I can't just do String name = jsonObject.getString("name"); because the name is the key, not the value.


JSONArray jArray =



[{
"Bob": {
"last-name": "Jorgenson",
"email": "b@b.com",
},

"Steve": {
"last-name": "Bobson",
"email": "steve@juno.com",
},
}]


So what's the best way to parse it with the dynamically-named keys?




Disclaimer


Yes, this is pretty basic stuff. The dynamic bit is throwing me off though. There are many similar questions, but they usual involve a number of other factors. I can successfully download the data and store it in the JSONArray jArray above. I just need to figure out how to parse the data as outlined above.


0 comments:

Post a Comment