它确实获取并打印信息,但随后崩溃.
作为一个iOS编程新手,我对下面的输出感到困惑(也请看the full output at PasteBin):
2014-01-21 21:21:10.873 oauthMailru[8228:3307] -[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x8a972902014-01-21 21:21:10.875 oauthMailru[8228:3307] *** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x8a97290'*** First throw call stack:( 0 CoreFoundation 0x01aa65e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x018298b6 objc_exception_throw + 44 2 CoreFoundation 0x01b43903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3 CoreFoundation 0x01a9690b ___forwarding___ + 1019 4 CoreFoundation 0x01a964ee _CF_forwarding_prep_0 + 14 5 oauthMailru 0x00003a62 __47-[VIEwController fetchMailruWithToken:ForUser:]_block_invoke + 402 6 Foundation 0x01545695 __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 151 7 Foundation 0x014a5945 -[NSBlockOperation main] + 88 8 Foundation 0x014fe829 -[__NSOperationInternal _start:] + 671 9 Foundation 0x0147b558 -[NSOperation start] + 83 10 Foundation 0x01500af4 __NSOQSchedule_f + 62 11 libdispatch.dylib 0x021344b0 _dispatch_clIEnt_callout + 14 12 libdispatch.dylib 0x02121018 _dispatch_async_redirect_invoke + 202 13 libdispatch.dylib 0x021344b0 _dispatch_clIEnt_callout + 14 14 libdispatch.dylib 0x02122eeb _dispatch_root_queue_drain + 287 15 libdispatch.dylib 0x02123137 _dispatch_worker_thread2 + 39 16 libsystem_pthread.dylib 0x024c0dab _pthread_wqthread + 336 17 libsystem_pthread.dylib 0x024c4cce start_wqthread + 30)libc++abi.dylib: terminating with uncaught exception of type NSException
有谁请知道发生了什么以及如何阅读此类崩溃?
我的源文件:ViewController.m,显示UIWebVIEw,然后转到DetailViewController.m
解决方法 您的代码认为JsON反序列化为对象(字典),但实际上它反序列化为包含一个对象的数组.试试这个:NSMutableArray *topLevelArray = [NSJsONSerialization JsONObjectWithData:data options:NSJsONReadingMutableContainers error:nil]; NSDictionary *dict = topLevelArray[0];
如果你想检查你得到的是什么,你可以使用isKindOfClass:像这样:
ID Jso = [NSJsONSerialization JsONObjectWithData:data options:NSJsONReadingMutableContainers error:nil];if (Jso == nil) { // Error. You should probably have passed an NSError ** as the error // argument so you Could log it.} else if ([Jso isKindOfClass:[NSArray class]]) { NSArray *array = Jso; // process array elements} else if ([Jso isKindOfClass:[NSDictionary class]]) { NSDictionary *dict = Jso; // process dictionary elements} else { // Shouldn't happen unless you use the NSJsONReadingallowFragments flag.}总结
以上是内存溢出为你收集整理的ios – [__NSArrayM objectForKeyedSubscript:]:无法识别的选择器发送到实例 – 附带源代码和截图全部内容,希望文章能够帮你解决ios – [__NSArrayM objectForKeyedSubscript:]:无法识别的选择器发送到实例 – 附带源代码和截图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)