我有問題解析從web服務的json消息中返回的字典對象。當AFNetworking成功解析它時,json是有效的。實際的響應如下:NSDictionary:無法解析[__NSCFNumber長度]:無法識別的選擇發送到實例
{
error = FALSE;
"error_desc" = "";
images = (
{
hasItem = 0;
image = "https://image/php4A6Xb8";
imageGroupId = 28;
"image_date" = "06/07/2014";
"image_id" = 863;
tag = "MCMOBILE-06072014-033902";
thumb = "https://image/thumbs/php4A6Xb8";
}
);
}
有了這個響應我的代碼執行以下操作:
- (void) successResponseImages: (NSDictionary *) dictionary {
NSLog(@"Success: %@", dictionary);
NSString *error = [ dictionary objectForKey:@"error"];
NSString *errorDesc = [ dictionary objectForKey:@"error_desc"];
NSArray *images = [ dictionary objectForKey:@"images"];
....
此時所有的值都是正確的,圖像是7個項目的數組。
我然後通過圖像使用盡量循環:
for (NSDictionary * image in images) {
NSLog([image objectForKey:@"image_id"]); <<<<fail
NSLog([image objectForKey:@"image"]);
NSLog([image objectForKey:@"thumb"]);
}
在它失敗了炸彈,出現以下錯誤:
2014-07-06 15:44:19.161 mycobber[8976:60b] -[__NSCFNumber length]: unrecognized selector sent to instance 0x9ad2690
我不知道是什麼問題。
編輯:更全面的堆棧跟蹤
2014-07-06 15:44:19.292 mycobber[8976:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x9ad2690'
*** First throw call stack:
(
0 CoreFoundation 0x0214f1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01ece8e5 objc_exception_throw + 44
2 CoreFoundation 0x021ec243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0213f50b ___forwarding___ + 1019
4 CoreFoundation 0x0213f0ee _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x020cf89c CFStringGetLength + 140
NSLog默認採用參數,不需要'stringWithFormat:'。只要放: 'NSLog(@「%@」,image [@「image_id」]);'。簡短而簡單。 – Milo