The way I do it is like this:

                try
                {
                        JSONArray mJsonArr = new JSONArray(jsonText); // your 
JSON text
MUST be valid
                        Iterator<String> mIteratorList =
mJsonArr.getJSONObject(0).keys(); // we retrieve the first object's
keys as an iterator

                        String text = "Key-Value pairs: ";
                        if (mIteratorList.hasNext())
                                while (mIteratorList.hasNext()) {
                                        String key = 
mIteratorList.next().toString();
                                        text += "\n " + key + " -> " +
mJsonArr.getJSONObject(0).getString(key);
                                }
                        else
                                text = "No iterators retrieved...";
                }
                catch (JSONException ex)
                {
                        text = "JSON Exception: " + ex.getMessage() + "\n";
                }
                catch (Exception ex)
                {
                        text = "Other Exception: " + ex.getMessage() + "\n";
                }

Maybe there's a better way to do this but this is how I did it before.
Hope this help you.

On Apr 7, 11:05 am, Maxood <[email protected]> wrote:
> I have the following JSON text that i need to parse to get pageName,
> pagePic, post_id, etc. What is the required code?
> pageInfo: {
> pageName: abc
> pagePic:http://profile.ak.fbcdn.net/object2/367/…}
>
> posts: [
> {
> post_id: 160119538822_302076968822
> actor_id: 1183856639
> picOfPersonWhoPosted:http://profile.ak.fbcdn.net/hprofile-ak-…
> nameOfPersonWhoPosted: Andrea Raquel
> message: Sounds cool. Can't wait to see it!
> likesCount: 2
> comments: [
> ]
> timeOfPost: 1266036226
>
>
>
> }

-- 
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

Reply via email to