On Thu, Dec 1, 2011 at 2:45 PM, s.rawat <[email protected]> wrote: > Hi , > I am trying to parse this json structure but am unable to do this ; > > { > "fruits": > [ > { > "apple": > { > "number":20, > "calories":"210", > "Sweet":"yes", > "Sour":"yes", > "Juice":"yes", > "Pickle":"No" > } > }, > { > "Grape": > { > "number":10, > "calories":"200", > "Sweet":"yes", > "Sour":"yes", > "Juice":"yes", > "Pickle":"No" > } > }, > { > "Banana": > { > "number":80, > "calories":"100", > "Sweet":"yes", > "Sour":"yes", > "Juice":"yes", > "Pickle":"yes" > } > }, > ] > } > > > > Here is my code : > > > jsonObject = new JSONObject(exteradata); > JSONArray cities = jsonObject.getJSONArray("cities"); > String json = cities.toString(); > String str = json; > char[] arr = str.toCharArray(); > for (char c : arr) > - > . > . > . > . > > Even though I am getting the individual characters from json structure like > {,",",c,i,t,i,e,s, from this code --> for (char c : arr) but actually i > want to fetch the individual attribute of the json string . > Does anyone have good link /idea to implement this.I have googled enough.
First, there is no "cities" array in your JSON. Second, you parse the string into a JSONArray... then convert it back into a string. If you want to iterate over the JSONArray, iterate over the JSONArray. http://stackoverflow.com/questions/1568762/jsonarray-with-java -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

