-1

我正在尝试获取 Twitter 提要。我正在使用这个网址

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

此 url 提供以下 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 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
4

1 回答 1

0

executeGenkFetch 似乎返回一个空数组或空字典数组。正如@ilmiacs 所说,发布推文的输出。

于 2012-10-09T13:21:49.863 回答