开发者

Items in NSDictionary returns NULL

开发者 https://www.devze.com 2023-03-10 21:47 出处:网络
I\'m using MGTWitterEngine and I cannot figure out why my dictionary items are returning null. I have this method:

I'm using MGTWitterEngine and I cannot figure out why my dictionary items are returning null.

I have this method:

- (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)c开发者_JS百科onnectionIdentifier{
NSDictionary *result = [searchResults objectAtIndex:0];
NSString *fromUser = [result valueForKey:@"from_user"];
NSLog(@"from user: %@", fromUser);
}

And for some reason, my NSLog always displays "from user: NULL". I can do an NSLog of searchResults which dumps the contents of the search correctly, but I can't figure out how to parse the information. Any help would be greatly appreciated.


Look at this question: Parsing Search Result with MGTwitterEngine in Objective C

They use:

- (void)searchResultsReceived:(NSArray *)searchResults 
                   forRequest:(NSString *)connectionIdentifier
{
    if ([searchResults count] > 0)
    {
        NSDictionary *result = [searchResults objectAtIndex:0];

        NSString *fromUser = [result valueForKey:@"from_user"];
        NSString *fromUserID = [result valueForKey@"from_user_id"];
        // ...
        NSString *text = [result valueForKey@"text"];

        NSLog(@"User %@(%@): %@", fromUser, fromUserID, text);
    }
}

It is similar to your code with a check on searchResults count.

0

精彩评论

暂无评论...
验证码 换一张
取 消