2012-10-09 162 views
-1

我正在嘗試獲取Twitter提要。我使用這個網址從twitter api獲取數據

https://twitter.com/status/user_timeline/wwwkrcgenkbe.json?count=25&from=wwwkrcgenkbe 

該網址提供了以下JSON格式

[ 

    { 
     "place": null, 
     "retweeted": false, 
     "in_reply_to_status_id_str": null, 
     "in_reply_to_screen_name": null, 
     "possibly_sensitive": false, 
     "in_reply_to_status_id": null, 
     "truncated": false, 
     "in_reply_to_user_id_str": null, 
     "user": { … }, 
     "in_reply_to_user_id": null, 
     "contributors": null, 
     "coordinates": null, 
     "retweet_count": 0, 
     "favorited": false, 
     "created_at": "Tue Oct 09 08:54:53 +0000 2012", 
     "geo": null, 
     "source": "<a href=\"http://www.facebook.com/twitter\" rel=\"nofollow\">Facebook</a>", 
     "id_str": "255592155345727489", 
     "id": 255592155345727500, 
     "possibly_sensitive_editable": true, 
     "text": "Vorige week won Nele Vangeneugden het shirtje dat Jelle Vossen droeg in de Europa League wedstrijd tegen... http://t.co/mwxSsBLP" 
    }, 

,我在下面的方法做。首先我添加這個方法。

for (NSDictionary *genkInfo in tweets) { 
      NSLog(@"Komt in deze methode"); 
      [Twitter twitterWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext]; 
      NSLog(@"tweets: %@", tweets); 
     } 

然後我以這種方式將值存儲在我的核心數據庫中。

+ (Twitter *)twitterWithGenkInfo:(NSDictionary *)genkInfo 
       inManagedObjectContext:(NSManagedObjectContext *)context 
{ 
    NSLog(@"till here"); 
    Twitter *twitter= nil; 
    NSLog(@"till here 2"); 
    twitter = [NSEntityDescription insertNewObjectForEntityForName:@"Twitter" 
               inManagedObjectContext:context]; 
    NSLog(@"tille here3"); 
    twitter.tweet  = [genkInfo objectForKey:TWITTER_TWEET]; 
    twitter.date  = [genkInfo objectForKey:TWITTER_DATE]; 
    NSLog(@"till here 4"); 
    NSLog(@"tweet is: %@",twitter.tweet); 
    NSLog(@"date is: %@",twitter.date); 

    return twitter; 
} 

這種方法在我的視圖控制器中按以下方式調用。

NSArray *tweets   = [GenkData getTweets]; 

for (NSDictionary *genkInfo in tweets) { 
       NSLog(@"Komt in deze methode"); 
       [Twitter twitterWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext]; 
      } 

但我總是得到這個錯誤。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKey:]: unrecognized selector sent to instance 0x2751678' 

任何人都可以幫忙嗎?

在此先感謝!

LOG文件

Log is: (
     { 
     contributors = "<null>"; 
     coordinates = "<null>"; 
     "created_at" = "Tue Oct 09 12:53:08 +0000 2012"; 
     favorited = 0; 
     geo = "<null>"; 
     id = 255652115341508608; 
     "id_str" = 255652115341508608; 
     "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>"; 
     "possibly_sensitive" = 0; 
     "possibly_sensitive_editable" = 1; 
     "retweet_count" = 0; 
     retweeted = 0; 
     source = "<a href=\"http://www.facebook.com/twitter\" rel=\"nofollow\">Facebook</a>"; 
     text = "KRC Genk mobile: de Iphone APP (al meer dan 1 mnd beschikbaar) werd reeds 2226 keer gedownload, de Android APP... http://t.co/QidTcLJS"; 
     truncated = 0; 
     user =   { 
      "contributors_enabled" = 0; 
      "created_at" = "Fri Nov 20 18:57:28 +0000 2009"; 
      "default_profile" = 0; 
      "default_profile_image" = 0; 
      description = "The official twitter account from Belgian Soccer team KRC Genk. Belgium champions 2011. Qualified for UEFA Euro League 2012-2013."; 
      "favourites_count" = 1; 
      "follow_request_sent" = "<null>"; 
      "followers_count" = 4831; 
      following = "<null>"; 
      "friends_count" = 21; 
      "geo_enabled" = 0; 
      id = 91402003; 
      "id_str" = 91402003; 
      "is_translator" = 0; 
      lang = en; 
      "listed_count" = 94; 
      location = "Genk - Belgium"; 
      name = "KRC Genk"; 
      notifications = "<null>"; 
      "profile_background_color" = C0DEED; 
      "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/84123014/youtubebg.jpg"; 
      "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/84123014/youtubebg.jpg"; 
      "profile_background_tile" = 0; 
      "profile_image_url" = "http://a0.twimg.com/profile_images/654317237/twitter_thumb_normal.jpg"; 
      "profile_image_url_https" = "https://si0.twimg.com/profile_images/654317237/twitter_thumb_normal.jpg"; 
      "profile_link_color" = 0084B4; 
      "profile_sidebar_border_color" = C0DEED; 
      "profile_sidebar_fill_color" = DDEEF6; 
      "profile_text_color" = 333333; 
      "profile_use_background_image" = 1; 
      protected = 0; 
      "screen_name" = wwwkrcgenkbe; 
      "statuses_count" = 4230; 
      "time_zone" = "<null>"; 
      url = "http://www.krcgenk.be"; 
      "utc_offset" = "<null>"; 
      verified = 0; 
     }; 
    }, 
-[__NSCFNumber managedObjectContext]: unrecognized selector sent to instance 0x9331b40 
+0

'NSLog(@「tweets:%@」,tweets)的後輸出''; – ilmiacs

+0

我已經編輯了一些日誌文章,感謝您的回答 – Steaphann

+0

'getTweets'中'[self executeGenkFetch:request]'的輸出。 (可能它沒有鍵'@「」'。) – ilmiacs

回答

0

executeGenkFetch似乎回到你空數組或空字典的數組。 正如@ilmiacs所說,發佈推文的輸出。

+0

首先謝謝你的回答,我用NSLog更新了我的代碼。但我認爲它沒有達到那個日誌。因爲它不打印任何東西 – Steaphann