由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'-[__NSArrayM objectForKey:]:无法识别的选择器发送到实例
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance
我正在尝试像这样更改以下数组。
实际响应:
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";
}
);
}
);
我想要的响应...
{
"start_dt" = "07:00:00";
}
{
"start_dt" = "11:00:00";
}
{
"start_dt" = "14:00:00";
}
我按照以下方式尝试了此操作,但最终获得了豁免。
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);
}
以下是我得到的异常..请帮助我..
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance
崩溃,因为 response
是一个数组而不是字典。 slot
也是一个数组而不是字典。
试试这个。
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);
或者在一行中。
NSString *startDate = [[[[response[@"slots"] firstObject] objectForKey:@"slot"] firstObject] objectForKey:@"start_dt"];
我正在尝试像这样更改以下数组。 实际响应:
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";
}
);
}
);
我想要的响应...
{
"start_dt" = "07:00:00";
}
{
"start_dt" = "11:00:00";
}
{
"start_dt" = "14:00:00";
}
我按照以下方式尝试了此操作,但最终获得了豁免。
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);
}
以下是我得到的异常..请帮助我..
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance
崩溃,因为 response
是一个数组而不是字典。 slot
也是一个数组而不是字典。
试试这个。
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);
或者在一行中。
NSString *startDate = [[[[response[@"slots"] firstObject] objectForKey:@"slot"] firstObject] objectForKey:@"start_dt"];