0

I'm trying to parse the Twitter User Status Updates JSON returned from Twitter:

NSDictionary *publicTimeline = [NSDictionary dictionaryWithJSONData:responseData error:&jsonParsingError];
NSLog(@"%@ - %@",publicTimeline,[publicTimeline class]);

This will give me the very tidy looking JSON returned from Twitter, but it says the class is _NSArrayI - which is confusing already, but I'm assuming it's some sort of Touch JSON peculiarity.

Once I have the dictionary though, I can't figure out how to do anything with it. If I try:

NSArray *array = [publicTimeline allKeys];

or

NSArray *tweetsArray = [dict objectForKey:@"results"];

...it crashes because of an unrecognized selector.

For the life of me I can't find any practical examples for how to use the Touch JSON library to actually grab objects. I mean, how do I grab the first Tweet? How about the date inside that tweet?

EDIT: This is what NSLog is saying it looks like:

(
    {
    contributors = "<null>";
    coordinates = "<null>";
    "created_at" = "Thu May 03 05:04:05 +0000 2012";
    favorited = 0;
    geo = "<null>";
    id = 197914401796403200;
    "id_str" = 197914401796403200;
    "in_reply_to_screen_name" = "<null>";
    "in_reply_to_status_id" = "<null>";
    "in_reply_to_status_id_str" = "<null>";
    "in_reply_to_user_id" = "<null>";
    "in_reply_to_user_id_str" = "<null>";
    place = "<null>";
    "retweet_count" = 4;
    retweeted = 0;
    source = "<a href=\"http://ubersocial.com\" rel=\"nofollow\">UberSocial for BlackBerry</a>";
    text = "Hear hear RT @saarsaar I am excited that more &amp; more entrepreneurs seem to be favoring VCs who help most, care most, &amp; love product";
    truncated = 0;
    user =         {
        "contributors_enabled" = 0;
        "created_at" = "Thu Apr 26 06:43:28 +0000 2007";
        "default_profile" = 0;
        "default_profile_image" = 0;
        description = "2x entrepreneur. Sold both companies (last to salesforce.com). Turned VC looking to invest in passionate entrepreneurs";
        "favourites_count" = 49;
        "follow_request_sent" = "<null>";
        "followers_count" = 65580;
        following = "<null>";
        "friends_count" = 835;
        "geo_enabled" = 0;
        id = 5520332;
        "id_str" = 5520332;
        "is_translator" = 0;
        lang = en;
        "listed_count" = 4501;
        location = "Los Angeles";
        name = "Mark Suster";
        notifications = "<null>";
        "profile_background_color" = 9AE4E8;
        "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/4977283/s_sunset23.jpg";
        "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/4977283/s_sunset23.jpg";
        "profile_background_tile" = 1;
        "profile_image_url" = "http://a0.twimg.com/profile_images/85156906/msuster_fb_normal.jpg";
        "profile_image_url_https" = "https://si0.twimg.com/profile_images/85156906/msuster_fb_normal.jpg";
        "profile_link_color" = 0000FF;
        "profile_sidebar_border_color" = 87BC44;
        "profile_sidebar_fill_color" = E0FF92;
        "profile_text_color" = 000000;
        "profile_use_background_image" = 1;
        protected = 0;
        "screen_name" = msuster;
        "show_all_inline_media" = 1;
        "statuses_count" = 14592;
        "time_zone" = "Pacific Time (US & Canada)";
        url = "http://bothsid.es";
        "utc_offset" = "-28800";
        verified = 0;
    };
},
    {
    contributors = "<null>";
    coordinates = "<null>";
    "created_at" = "Wed May 02 04:37:36 +0000 2012";
    favorited = 0;
    geo = "<null>";
    id = 197545349622153217;
    "id_str" = 197545349622153217;
    "in_reply_to_screen_name" = "<null>";
    "in_reply_to_status_id" = "<null>";
    "in_reply_to_status_id_str" = "<null>";
    "in_reply_to_user_id" = "<null>";
    "in_reply_to_user_id_str" = "<null>";
    place = "<null>";
    "retweet_count" = 23;
    retweeted = 0;
    "retweeted_status" =         {
        contributors = "<null>";
        coordinates = "<null>";
        "created_at" = "Wed May 02 04:21:30 +0000 2012";
        favorited = 0;
        geo = "<null>";
        id = 197541298746568704;
        "id_str" = 197541298746568704;
        "in_reply_to_screen_name" = "<null>";
        "in_reply_to_status_id" = "<null>";
        "in_reply_to_status_id_str" = "<null>";
        "in_reply_to_user_id" = "<null>";
        "in_reply_to_user_id_str" = "<null>";
        place = "<null>";
        "retweet_count" = 23;
        retweeted = 0;
        source = "<a href=\"http://twitter.com/#!/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>";
        text = "When I hear the word 'pivot', in my head I hear the sound of a toilet flushing. Cc @infoarbitrage @msuster";
        truncated = 0;
        user =             {
            "contributors_enabled" = 0;
            "created_at" = "Tue Apr 22 13:08:40 +0000 2008";
            "default_profile" = 0;
            "default_profile_image" = 0;
            description = "Entrepreneur turned Investor. Chief Firestarter at @K9Ventures. Tags: tech entrepreneur startups angel investor concept seed web venture vc cmu stanford";
            "favourites_count" = 7;
            "follow_request_sent" = "<null>";
            "followers_count" = 9732;
            following = "<null>";
            "friends_count" = 1009;
            "geo_enabled" = 1;
            id = 14474225;
            "id_str" = 14474225;
            "is_translator" = 0;
            lang = en;
            "listed_count" = 628;
            location = "Palo Alto, CA";
            name = "Manu Kumar";
            notifications = "<null>";
            "profile_background_color" = 303030;
            "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/3375189/logo90x100__with_margin_.png";
            "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/3375189/logo90x100__with_margin_.png";
            "profile_background_tile" = 0;
            "profile_image_url" = "http://a0.twimg.com/profile_images/1772187320/Manu_Kumar__813x961__normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/1772187320/Manu_Kumar__813x961__normal.jpg";
            "profile_link_color" = F6901E;
            "profile_sidebar_border_color" = 999999;
            "profile_sidebar_fill_color" = 626465;
            "profile_text_color" = 303030;
            "profile_use_background_image" = 1;
            protected = 0;
            "screen_name" = ManuKumar;
            "show_all_inline_media" = 1;
            "statuses_count" = 11234;
            "time_zone" = "Pacific Time (US & Canada)";
            url = "http://www.k9ventures.com";
            "utc_offset" = "-28800";
            verified = 0;
        };
    };
    source = web;
    text = "RT @ManuKumar: When I hear the word 'pivot', in my head I hear the sound of a toilet flushing. Cc @infoarbitrage @msuster";
    truncated = 0;
    user =         {
        "contributors_enabled" = 0;
        "created_at" = "Thu Apr 26 06:43:28 +0000 2007";
        "default_profile" = 0;
        "default_profile_image" = 0;
        description = "2x entrepreneur. Sold both companies (last to salesforce.com). Turned VC looking to invest in passionate entrepreneurs";
        "favourites_count" = 49;
        "follow_request_sent" = "<null>";
        "followers_count" = 65580;
        following = "<null>";
        "friends_count" = 835;
        "geo_enabled" = 0;
        id = 5520332;
        "id_str" = 5520332;
        "is_translator" = 0;
        lang = en;
        "listed_count" = 4501;
        location = "Los Angeles";
        name = "Mark Suster";
        notifications = "<null>";
        "profile_background_color" = 9AE4E8;
        "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/4977283/s_sunset23.jpg";
        "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/4977283/s_sunset23.jpg";
        "profile_background_tile" = 1;
        "profile_image_url" = "http://a0.twimg.com/profile_images/85156906/msuster_fb_normal.jpg";
        "profile_image_url_https" = "https://si0.twimg.com/profile_images/85156906/msuster_fb_normal.jpg";
        "profile_link_color" = 0000FF;
        "profile_sidebar_border_color" = 87BC44;
        "profile_sidebar_fill_color" = E0FF92;
        "profile_text_color" = 000000;
        "profile_use_background_image" = 1;
        protected = 0;
        "screen_name" = msuster;
        "show_all_inline_media" = 1;
        "statuses_count" = 14592;
        "time_zone" = "Pacific Time (US & Canada)";
        url = "http://bothsid.es";
        "utc_offset" = "-28800";
        verified = 0;
    };
}

)

startuprob
  • 1,917
  • 5
  • 30
  • 45
  • What does publicTimeline look like? Since your log says it's an array, of course allKeys and objectForKey will crash. Can you show an example of what you're getting from the dictionaryWithJSONData: method? – rdelmar May 03 '12 at 21:55

1 Answers1

0

That is an array with just 2 objects (I think, I can't quite line up all the curly braces), so try using objectAtIndex:0 to get the first dictionary, and see if that solves your problem.

rdelmar
  • 103,982
  • 12
  • 207
  • 218