2012-02-21 5 views
2

私はiOS開発には新しく、JSONツイッターフィードの値を解析したいので、それらをtableViewに取り込むことができます。JSONフィードの解析iOS 5

これまでのところ、フィードの情報がコンソールバーに文字列として記録されていましたが、次にどこに行くのかがわかりません。

私の現在のコードは次のとおりです。

私のフィードからの生データを提供します
- (void)loadTweets 
{ 
NSString *twitterURL = [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/user_timeline.json?screen_name=evostikleague&count=%d", tweetCellCount];  
NSURL *fullURL = [NSURL URLWithString:twitterURL]; 

NSError *error = nil; 
NSData *dataURL = [NSData dataWithContentsOfURL:fullURL options:0 error:&error]; 

NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]; 

NSLog(@"Everything:\n%@", strResult); 
} 

[{"id_str":"171930825225551872","coordinates":null,"in_reply_to_status_id_str":null,"place":null,"possibly_sensitive":false,"geo":null,"in_reply_to_user_id_str":null,"favorited":false,"created_at":"Tue Feb 21 12:14:37 +0000 2012","user":{"id":148344608,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","created_at":"Wed May 26 13:24:44 +0000 2010","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_text_color":"333333","time_zone":null,"following":null,"followers_count":2441,"profile_sidebar_border_color":"C0DEED","screen_name":"evostikleague","verified":false,"utc_offset":null,"default_profile_image":false,"location":"UK","name":"The Evo-Stik League","notifications":null,"profile_background_tile":false,"favourites_count":0,"id_str":"148344608","profile_sidebar_fill_color":"DDEEF6","contributors_enabled":false,"protected":false,"show_all_inline_media":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_background_color":"C0DEED","description":"","default_profile":true,"lang":"en","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","statuses_count":1296,"geo_enabled":false,"profile_link_color":"0084B4","follow_request_sent":null,"friends_count":178,"listed_count":43,"profile_use_background_image":true,"url":"http:\/\/www.evostikleague.co.uk\/"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"retweeted":false,"in_reply_to_status_id":null,"contributors":null,"truncated":false,"source":"\u003Ca href=\"http:\/\/twitterfeed.com\" rel=\"nofollow\"\u003Etwitterfeed\u003C\/a\u003E","id":171930825225551872,"retweet_count":1,"text":"The Evo-Stik Challenge: League announce sponsored bike ride from Wembley to Blackpool http:\/\/t.co\/23i8gC2N"},{"id_str":"171915587491078144","coordinates":null,"in_reply_to_status_id_str":null,"place":null,"possibly_sensitive":false,"geo":null,"in_reply_to_user_id_str":null,"favorited":false,"created_at":"Tue Feb 21 11:14:04 +0000 2012","user":{"id":148344608,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","created_at":"Wed May 26 13:24:44 +0000 2010","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_text_color":"333333","time_zone":null,"following":null,"followers_count":2441,"profile_sidebar_border_color":"C0DEED","screen_name":"evostikleague","verified":false,"utc_offset":null,"default_profile_image":false,"location":"UK","name":"The Evo-Stik League","notifications":null,"profile_background_tile":false,"favourites_count":0,"id_str":"148344608","profile_sidebar_fill_color":"DDEEF6","contributors_enabled":false,"protected":false,"show_all_inline_media":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_background_color":"C0DEED","description":"","default_profile":true,"lang":"en","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","statuses_count":1296,"geo_enabled":false,"profile_link_color":"0084B4","follow_request_sent":null,"friends_count":178,"listed_count":43,"profile_use_background_image":true,"url":"http:\/\/www.evostikleague.co.uk\/"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"retweeted":false,"in_reply_to_status_id":null,"contributors":null,"truncated":false,"source":"\u003Ca href=\"http:\/\/twitterfeed.com\" rel=\"nofollow\"\u003Etwitterfeed\u003C\/a\u003E","id":171915587491078144,"retweet_count":0,"text":"Gingerbreads look to consolidate top spot: Grantham Town update, by Graham Cowell http:\/\/t.co\/FREdshtm"},{"id_str":"171633185870979074","coordinates":null,"in_reply_to_status_id_str":null,"place":null,"possibly_sensitive":false,"geo":null,"in_reply_to_user_id_str":null,"favorited":false,"created_at":"Mon Feb 20 16:31:54 +0000 2012","user":{"id":148344608,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","created_at":"Wed May 26 13:24:44 +0000 2010","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_text_color":"333333","time_zone":null,"following":null,"followers_count":2441,"profile_sidebar_border_color":"C0DEED","screen_name":"evostikleague","verified":false,"utc_offset":null,"default_profile_image":false,"location":"UK","name":"The Evo-Stik League","notifications":null,"profile_background_tile":false,"favourites_count":0,"id_str":"148344608","profile_sidebar_fill_color":"DDEEF6","contributors_enabled":false,"protected":false,"show_all_inline_media":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_background_color":"C0DEED","description":"","default_profile":true,"lang":"en","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","statuses_count":1296,"geo_enabled":false,"profile_link_color":"0084B4","follow_request_sent":null,"friends_count":178,"listed_count":43,"profile_use_background_image":true,"url":"http:\/\/www.evostikleague.co.uk\/"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"retweeted":false,"in_reply_to_status_id":null,"contributors":null,"truncated":false,"source":"\u003Ca href=\"http:\/\/twitterfeed.com\" rel=\"nofollow\"\u003Etwitterfeed\u003C\/a\u003E","id":171633185870979074,"retweet_count":1,"text":"Chasetown unveil \u00a310k Makeover: Premier Division club won Evo-Stik Facilities Makeover competition http:\/\/t.co\/ywf74N9f"}] 

私は、配列にボブにこれをしたいので、私は量を増やすことができます結果を返し、ループスルーして表に表示します。

答えて

1

iOS 5では、AppleはついにJSON Parserを公開しました。

あなたのコードは次のようになりますが、私は最初のドキュメントを読んで示唆NSJSONSerialization

を見てみてください。ここで

NSArray* yourArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:someError] 
+2

:)です。それはかなり便利です:) –

0
- (void)loadTweets 
    { 
    NSString *twitterURL = [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/user_timeline.json?screen_name=evostikleague&count=%d", tweetCellCount];  
    NSURL *fullURL = [NSURL URLWithString:twitterURL]; 

    NSError *error = nil; 
    NSData *dataURL = [NSData dataWithContentsOfURL:fullURL options:0 error:&error]; 
    id result=[NSJSONSerialization JSONObjectWithData:dataURL options: 
        NSJSONReadingMutableContainers error:&error]; 
    NSLog("JSON data:%@", result); 
    //NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]; 

    //NSLog(@"Everything:\n%@", strResult); 
    } 

あなたはNSJSONSerializationは、上記のIOS 5とでのみ使用可能ですので、あなたは、代わりにJSONKitを使用する場合があります

関連する問題