我正在尝试使用 AFNetworking 在 json 中接收某个值。该值仅包含数字,我想将其作为 NSString 接收。当我比较接收到的值时,我得到一个异常(这个帖子后面也会提到异常)
这是产生错误的编码。
NSArray *overallGameResultsArray = [resultDictionary valueForKey:@"overall_game_results"];
winCountDictionary = [[NSDictionary alloc] init];
for (NSDictionary *gameResultsDictionary in overallGameResultsArray)
{
NSString *userId = [gameResultsDictionary valueForKey:@"winner_user_id"];
NSString *winCount = [gameResultsDictionary valueForKey:@"win_count"];
if ([winCount isEqualToString:@"0"])
{
NSLog(@"0 wins");
}
}
如果评论了“如果比较”,我不会得到例外。win_count 仅由 JSON 响应中的数字组成。
以下是我得到的异常错误。
2012-10-10 15:41:35.086 FMB[3549:c07] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7230af0 2012-10-10 15:41:35.086 FMB[3549:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7230af0'
*** First throw call stack: (0x1638012 0x1345e7e 0x16c34bd 0x1627bbc 0x162794e 0x11e03 0x20583 0x1fab4 0x245053f 0x2462014 0x24527d5 0x15deaf5 0x15ddf44 0x15dde1b 0x26997e3 0x2699668 0x28d65c 0x2512 0x2445) libc++abi.dylib: terminate called throwing an exception