gpt4 book ai didi

ios - [__NSArrayM objectForKeyedSubscript :]: unrecognized selector sent to instance - source code and screenshot attached

转载 作者:可可西里 更新时间:2023-11-01 06:17:51 28 4
gpt4 key购买 nike

在 GitHub 我有 a simple iPhone app ,它从社交网络 Mail.ru 获取用户信息(通过使用 OAuth):

app screenshot

它确实获取并打印了信息,但随后崩溃了。

作为 iOS 编程新手,我对下面的输出感到困惑(另请参阅 the full output at PasteBin ):

2014-01-21 21:21:10.873 oauthMailru[8228:3307] -[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x8a97290
2014-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 :]: unrecognized selector sent to instance - source code and screenshot attached,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21268539/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com