我从服务器获得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'
答案 0 :(得分:1)
获取下面的response
NSArray *yourArry = [NSJSONSerialization JSONObjectWithData:JSONData
options:kNilOptions error:& error];
在firstName
didselectrowatindexpath
的任何价值,如下所示
NSString *firstName=[NSString stringWithFormat:@"%@",
[[yourArry objectAtIndex:indexPath.row]valueForKey:@"firstName"]];