繁体   English   中英

应用程序崩溃并出现错误 [__NSCFDictionary objectAtIndex:]:无法识别的选择器发送到实例

[英]App crashes with error [__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance

我从服务器得到 json 响应作为 json 数组。

[{
    "id": 514524,
    "firstName": "aa",
    "lastName": "vv",
    "fullName": "aa vv"
}, {
    "id": 51411524,
    "firstName": "qq",
    "lastName": "vv",
    "fullName": "qq vv"
}]

但是,如果我在didSelectRowAtIndexpath使用indexPath.row访问该数组的元素,如下所示,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    ProfileViewController *obj = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil]; 
    obj.isFromScreen = @"Authorized People"; 
    obj.profileArray = [authorizedPeopleArray objectAtIndex:indexPath.row]; 
    [self.navigationController pushViewController:obj animated:YES]; 
}

我收到一个错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x7aa78d20'

得到你的response如下

NSArray *yourArry = [NSJSONSerialization JSONObjectWithData:JSONData
    options:kNilOptions error:& error];

didselectrowatindexpath获取例如firstName任何值,如下所示

NSString *firstName=[NSString stringWithFormat:@"%@",
        [[yourArry objectAtIndex:indexPath.row]valueForKey:@"firstName"]];

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM