Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJessica Wright
2,137 PointsHow do I iterate through a list of jsonObjects without any Arrays included. Just back to back objects? {::},{::},{::}
My jsonData and jsonObject obviously has the same info. I copied the json from my android monitor: {"id":"01","name":"Bill","salary":"50"}, {"id":"02","name":"James","salary":"60"}, {"id":"03","name":"Ethan","salary":"70"}
How can I iterate through my jsonObject so I can separate the three objects so I can get all of the values for my customized object? When I loop through this it makes 3 new instances with ALL three objects contain the same values as the first jsonObject (01,Bill,50). I have looked this up tirelessly but everything thing I have seen has and array included in the jsonData which would make things easier but this response Body is coming straight from a database - no arrays, just back to back objects. Iterating only gives me keys which I already did in a separate method. Now I need the values. Thanks!
1 Answer
Seth Kroger
56,413 PointsHave you tried parsing the response directly into a JSONArray instead of using a JSONObject first? The response is, after all, an array of JSON objects. It's only missing the outer brackets, [], and the parser is a bit lenient about syntax.
Jessica Wright
2,137 PointsJessica Wright
2,137 PointsThanks Seth. I'm sorry for the late get back. Didn't know you answered because my notification went to spam. Anyway what I decided to do what parse the database info on the PHP side so that my output would be surrounded by the outer brackets thus now receiving what I need in JSON array form. Thank you for your response and help.