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

时间:2016-09-20 12:40:03

标签: ios objective-c

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

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

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

- (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'

1 个答案:

答案 0 :(得分:1)

获取下面的response

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

firstName

中获取以下didselectrowatindexpath的任何价值,如下所示
NSString *firstName=[NSString stringWithFormat:@"%@",
        [[yourArry objectAtIndex:indexPath.row]valueForKey:@"firstName"]];