“ – :无法识别的select器发送到实例”错误没有NSDictionary?

在我的代码中,当我按下一个button来打开一个popup屏幕时,它应该从网站获取数据并将其存储在一个string中,然后将该string放到popup屏幕上的文本视图中。 当我运行程序,并按下button来到popup窗口,我得到一个SIGABRT错误和“ – [__ NSDictionaryI长度]:无法识别的select发送到实例”。 在研究了这个之后,我发现当你试图将NSDictionary引用到一个长度方法的时候,就会出现这个错误。 我没有在我的代码NSDictionary,所以我不知道是什么原因造成的错误。

错误信息

[76416:60b] – [ NSDictionaryI长度]:无法识别的select发送到实例0x8f8ece0 2014-08-13 16:41:59.248 CWSGui [76416:60b] *由于未捕获的exception'NSInvalidArgumentException',原因:' – [__ NSDictionaryI长度]:无法识别的select器发送到实例0x8f8ece0' *第一个抛出调用堆栈:(0 CoreFoundation 0x01c0d1e4 __exceptionPreprocess + 180 1 libobjc.A.dylib
0x0198c8e5 objc_exception_throw + 44 2 CoreFoundation
0x01caa243 – [NSObject(NSObject)doesNotRecognizeSelector:] + 275 3
CoreFoundation 0x01bfd50b ___forwarding_ + 1019 4 CoreFoundation 0x01bfd0ee _CF_forwarding_prep_0 + 14 5 Foundation 0x015aa4e4 – [NSConcreteAttributedString length] + 42 6 Foundation
0x015a9a6c – [NSConcreteAttributedString initWithString:attributes:] + 182 7 UIKit 0x00d5ae9d – [UITextView setText:] + 125 8 CWSGui 0x0000805e – [SystemLog viewDidAppear:] + 686 9 UIKit 0x0076f099 – [UIViewController _setViewAppearState:isAnimating:] + 526 10 UIKit 0x0076f617 – [UIViewController viewDidAppear:] + 146 11 UIKit 0x00771014 __64- [UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] _ block_invoke + 44 12 UIKit 0x0076f9aa – [UIViewController _executeAfterAppearanceBlock] + 63 13 UIKit 0x0066a0d0 ___afterCACommitHandler_block_invoke_2 + 33 14 UIKit
0x0066a055 _applyBlockToCFArrayCopiedToStack + 403 15 UIKit
0x00669e9a _afterCACommitHandler + 568 16 CoreFoundation
0x01bd536e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 17 CoreFoundation 0x01bd52bf __CFRunLoopDoObserver + 399 18 CoreFoundation 0x01bb3254 __CFRunLoopRun + 1076 19 CoreFoundation 0x01bb29d3 CFRunLoopRunSpecific + 467 20 CoreFoundation
0x01bb27eb CFRunLoopRunInMode + 123 21 GraphicsServices
0x03a3d5ee GSEventRunModal + 192 22graphics服务
0x03a3d42b GSEventRun + 104 23 UIKit
0x0064cf9b UIApplicationMain + 1225 24 CWSGui
0x00008e2d main + 141 25 libdyld.dylib
0x024be701 start + 1)libc ++ abi.dylib:以NSExceptiontypes的未捕获exception

查看出现

- (void)viewDidAppear:(BOOL)animated { NSUserDefaults *ipdefaults = [NSUserDefaults standardUserDefaults]; IPString = [ipdefaults objectForKey:@"IP"]; NSString *http = @"http://"; NSString *IPMiddle = [http stringByAppendingString:IPString]; NSString *IPFinal = [IPMiddle stringByAppendingString:@"/tasks"]; NSLog(@"Final IP: %@", IPFinal); //array stuff from the ip array = [[NSMutableArray alloc]init]; //make a connection [self getIPWithIP:IPFinal]; NSString *str=@"http://example.com"; NSURL *url=[NSURL URLWithString:str]; NSData *data=[NSData dataWithContentsOfURL:url]; NSError *error=nil; NSString *string = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:&error]; NSLog(@"Your JSON Object: %@", string); textField.text = string; } 

 [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:&error]; 

永远不会返回一个string。 NSArray或NSDictionary。 (文档只承诺: 来自JSON数据的基础对象,如果发生错误,则为零,所以将来可能是另一种types)。

你错误开始

– [NSDictionaryI长度]:

所以在你的情况下它是一个字典(NSDictionaryI是NSDictionary的具体不可变的子类)。

只是因为你inputvariablesNSString它不会改变分配给它的对象。

你正试图得到一个实际上是一个NSDictionaryNSString的长度。 这可能是一些JSONparsing的结果。