我試圖使用AFNetworking在json中接收某個值。該值只包含數字,我想將其作爲NSString接收。當我比較接收到的值時,我得到一個異常(例外情況也在本文後面提到)AFNetworking不會返回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
我懷疑問題在於您收到的JSON或您提出的請求。沒有這些更多的細節,不可能回答你的問題。 –