简体   繁体   English

iOS - 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序

[英]iOS - Terminating app due to uncaught exception 'NSInvalidArgumentException'

So I am really new at developing for iOS, and I've been doing my best, to search for an answer, to debug it and anything I could come up with. 所以我真的很擅长开发iOS,我一直在努力,寻找答案,调试它以及我能想到的任何东西。

Though, I haven't been able to find a solution to the issue. 虽然,我一直无法找到解决问题的办法。

I've been trying to fetch an external JSON document, which works fine, but when it comes to parsing it, it buggers up. 我一直在尝试获取一个外部JSON文档,它工作正常,但是当解析它时,它就会出错。

First of all, this is the error message I'm getting, the whole lot of it. 首先,这是我得到的错误信息,它的全部内容。

2013-01-31 22:40:19.261 demodh[6205:c07] View Loaded
2013-01-31 22:40:19.479 demodh[6205:c07] -[__NSCFStringcountByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7554f90 
2013-01-31 22:40:19.480 demodh[6205:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7554f90'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0x28d3 0xbd6589 0xbd4652 0xbd589a 0xbd460d 0xbd4785 0xb21a68 0x4615911 0x4614bb3 0x4652cda 0x1c358fd 0x465335c 0x46532d5 0x453d250 0x1c16f3f 0x1c1696f 0x1c39734 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x1d6d 0x1c95 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

And this is the code I'm using at the moment: 这是我目前正在使用的代码:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];

    for(NSDictionary *dict in allDataDictionary)
    {
        if (![allDataDictionary isKindOfClass:[NSDictionary class]])
        {
            NSLog(@"2Unable to process temp array because it's an instance of %@", [allDataDictionary class]);
        }
        else
        {
            for(NSDictionary *deal in dict)
            {
                if (![deal isKindOfClass:[NSDictionary class]])
                {
                    NSLog(@"Unable to process temp array because it's an instance of %@", [deal class]);
                }
                else
                {
                    NSString *title = [deal objectForKey:@"title"];
                    NSLog(title);
                }
            }
        }

    }
}

And the JSON I'm loading is: Link 我正在加载的JSON是: 链接

I hope you're able to assist me in finding a solution. 我希望你能帮助我找到解决方案。

The problem is you're fast-enumerating a NSDictionary and expecting to get its values, when in fact you'll get its keys. 问题是你快速枚举一个NSDictionary并希望得到它的值,而实际上你会获得它的密钥。 When you try to fast-enumerate an NSString you get the assertion you're seeing. 当您尝试快速枚举NSString您将获得您所看到的断言。 You probably wanted this: 你可能想要这个:

for(NSObject *key in allDataDictionary) {
    NSDictionary *dict = allDataDictionary[key];
    ...
    for (NSObject *dealKey in dict) {
         NSDictionary *deal = dict[dealKey];
    }
    ...

Alternatively, if you really want to enumerate the values and don't need the keys: 或者,如果您真的想要枚举值并且不需要键:

for(NSDictionary *dict in [allDataDictionary allValues]) {
    ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS应用程序异常-由于未捕获的异常'NSInvalidArgumentException'而终止应用程序 - iOS App Exception - Terminating app due to uncaught exception 'NSInvalidArgumentException' 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序 - ios google 登录 - Terminating app due to uncaught exception 'NSInvalidArgumentException' - ios google sign in 由于未捕获的异常“NSInvalidArgumentException”,iOS 上的 React Native 崩溃并终止应用程序 - React Native on iOS crashes with Terminating app due to uncaught exception 'NSInvalidArgumentException' “因未捕获的异常而终止应用程序'NSInvalidArgumentException'” - “Terminating app due to uncaught exception 'NSInvalidArgumentException'” 由于未捕获的异常'NSInvalidArgumentException 4而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException 4 ***由于未捕获的异常'NSInvalidArgumentException'而终止应用, - *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 由于未捕获而终止应用程序 > 异常“NSInvalidArgumentException” - Terminating app due to uncaught > exception 'NSInvalidArgumentException' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,NSUserDefaults? - Terminating app due to uncaught exception 'NSInvalidArgumentException', NSUserDefaults? 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序, - Terminating app due to uncaught exception 'NSInvalidArgumentException', 由于未捕获的异常NSInvalidArgumentException而终止应用程序 - Terminating app due to uncaught exception NSInvalidArgumentException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM