简体   繁体   English

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSArrayM objectForKey:]:无法识别的选择器已发送至实例

[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance

I'm trying to alter the following array like this. 我正在尝试像这样更改以下数组。 Actual Response: 实际回应:

 errFlag = 0;
    errMsg = "Got Slot successfully.";
    errNum = 128;
    slots =     (
                {
            date = "";
            slot =             (
                                {
                    booked = 1;
                    end = 1510822800;
                    "end_dt" = "09:00:00";
                    id = 5a02a0372279511b1c968a10;
                    locId = "";
                    radius = 1;
                    "slot_price" = 20;
                    start = 1510815600;
                    "start_dt" = "07:00:00";
                }
            );
        }
    );

The response I want it like... 我想要的回应就像...

{
 "start_dt" = "07:00:00";
                    }
{
 "start_dt" = "11:00:00";
                    }
{
 "start_dt" = "14:00:00";
                    }

I Attempted this on following way but I ended up with an excemption. 我尝试按照以下方式进行尝试,但最终获得了豁免。

if (requestType == RequestTypeGetAllMetSlots)
        {

            // altering the response into an array
            NSDictionary *slotResultsDict = response[@"slots"];
            NSLog(@"Priniting timeSlotResponseDict%@",slotResultsDict);
            timeSlotResponseArray = [[slotResultsDict objectForKey:@"slot"] valueForKey:@"start_dt"];
            NSLog(@"Priniting timeSlotResponseArray%@",timeSlotResponseArray);


        }

Following is the Exeception I got.. Please help me.. 以下是我得到的感受。.请帮助我..

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance

Crashing because response is an array not dictionary. 由于response是数组而不是字典而崩溃。 And slot is also an array not dictionary. 而且slot也是数组而不是字典。

Try this. 尝试这个。

NSArray *slots = response[@"slots"]
NSDictionary *slotResultsDict = [slots firstObject];
NSLog(@"Priniting timeSlotResponseDict%@",slotResultsDict);

NSDictionary *subSlot = [[slotResultsDict objectForKey:@"slot"] firstObject];
timeSlotResponseArray = [subSlot valueForKey:@"start_dt"];
NSLog(@"Priniting timeSlotResponseArray%@",timeSlotResponseArray);

Or in one line. 或一行。

NSString *startDate = [[[[response[@"slots"] firstObject] objectForKey:@"slot"] firstObject] objectForKey:@"start_dt"];

暂无
暂无

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

相关问题 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:NSArrayM objectForKey - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: NSArrayM objectForKey 由于未捕获的异常'NSInvalidArgumentException'无法识别的选择器发送到实例而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException' unrecognized selector sent to instance 终止应用程序-'NSInvalidArgumentException',原因:'-[NSCFString objectForKey:]:无法识别的选择器已发送到实例 - Terminating app - 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSCFArray length]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance ***由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[__ NSDictionaryM名称]:无法识别的选择器已发送到实例 - *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM Name]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSNull长度]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:-[__ NSCFString方案]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: -[__NSCFString scheme]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSCFType next]:无法识别的选择器已发送至实例' - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType next]: unrecognized selector sent to instance ' 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSCFString size]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString size]: unrecognized selector sent to instance iOS-由于未捕获的异常'NSInvalidArgumentException无法识别的选择器发送到实例0x7a9a2c0'而终止应用程序 - IOS - Terminating app due to uncaught exception 'NSInvalidArgumentException unrecognized selector sent to instance 0x7a9a2c0'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM