我正在尝试解析从 Twitter 返回的 Twitter 用户状态更新 JSON:
NSDictionary *publicTimeline = [NSDictionary dictionaryWithJSONData:responseData error:&jsonParsingError];
NSLog(@"%@ - %@",publicTimeline,[publicTimeline class]);
这会给我从 Twitter 返回的看起来非常整洁的 JSON,但它说该类是 _NSArrayI - 这已经令人困惑,但我假设它是某种 Touch JSON 特性。
但是,一旦我有了字典,我就无法弄清楚如何用它做任何事情。如果我尝试:
NSArray *array = [publicTimeline allKeys];
或者
NSArray *tweetsArray = [dict objectForKey:@"results"];
...由于无法识别的选择器而崩溃。
在我的一生中,我找不到任何关于如何使用 Touch JSON 库来实际抓取对象的实际示例。我的意思是,我如何获取第一条推文?那条推文中的日期怎么样?
编辑:这就是 NSLog 所说的:
(
{
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 & more entrepreneurs seem to be favoring VCs who help most, care most, & 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;
};
}
)