这个for循环有什么问题 - 试图用Tweet对象填充数组?

Ric*_*nop 2 iphone xcode objective-c ios

基本上,我有一个包含时间轴的Twitter API的JSON响应.我试图在循环中填充和数组与Tweet对象,但警报窗口告诉我循环后数组是空的:

    NSError *error;

    NSArray *tweetJsonObjects = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    for (int i = 0; i < [tweetJsonObjects count]; i++) {
        Tweet *tweet = [[Tweet alloc] init];
        tweet.userName = [[[tweetJsonObjects objectAtIndex:i] objectForKey:@"user"] objectForKey:@"name"];
        tweet.text = [[tweetJsonObjects objectAtIndex:i] objectForKey:@"text"];
        //[tweet.text gtm_stringByUnescapingFromHTML];
        tweet.userProfileImageUrl = [[[tweetJsonObjects objectAtIndex:i] objectForKey:@"user"] objectForKey:@"profile_image_url"];
        [tweets addObject:tweet];
    }

    NSString *x = [NSString stringWithFormat:@"%d", [tweets count]];
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                      message:x
                                                     delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
    [message show];
Run Code Online (Sandbox Code Playgroud)

Tweet对象非常简单:

@interface Tweet : NSObject
{
    NSString *userName;
    NSString *text;
    NSString *userProfileImageUrl;
    UIImage *userProfileImage;
}

@property (nonatomic, retain) NSString *userName;
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSString *userProfileImageUrl;
@property (nonatomic, retain) UIImage *userProfileImage;
@end
Run Code Online (Sandbox Code Playgroud)

das*_*ght 5

我想这是因为你打电话indexOfObject:而不是addObject:- 一个无辜的自动完成错误.