Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 向数组添加对象,数组返回null_Objective C_Arrays_Nsmutablearray - Fatal编程技术网

Objective c 向数组添加对象,数组返回null

Objective c 向数组添加对象,数组返回null,objective-c,arrays,nsmutablearray,Objective C,Arrays,Nsmutablearray,我有两个数组,它们从数据库接收信息。其中一个名为json,包含具有用户id的帖子,另一个名为userJson,包含具有用户id的所有用户。如果来自json的用户id等于来自userJson的用户id,我想用该用户用户名填充第三个数组。我正在使用以下代码: NSDictionary *info = [json objectAtIndex:indexPath.row]; NSDictionary *userInfo = [userArray objectAtIndex:0]; for (int i=

我有两个数组,它们从数据库接收信息。其中一个名为json,包含具有用户id的帖子,另一个名为userJson,包含具有用户id的所有用户。如果来自json的用户id等于来自userJson的用户id,我想用该用户用户名填充第三个数组。我正在使用以下代码:

NSDictionary *info = [json objectAtIndex:indexPath.row];
NSDictionary *userInfo = [userArray objectAtIndex:0];
for (int i=0; i<[json count]; i++) {
    if ([[userInfo objectForKey:@"user_id"] isEqualToString:[info objectForKey:@"user_id"]]) {
        [usernameArray addObject:[userInfo objectForKey:@"username"]];
    }
}

NSLog(@"%@", usernameArray);
NSDictionary*info=[json-objectAtIndex:indexath.row];
NSDictionary*userInfo=[userArray objectAtIndex:0];

对于(int i=0;i您需要首先添加以下内容:

usernameArray = [[NSMutableArray alloc]init];
然后将循环更改为以下内容:

NSDictionary *info = [json objectAtIndex:indexPath.row];
NSDictionary *userInfo;
for (int i=0; i<[userArray count]; i++) {
    userInfo = [userArray objectAtIndex:i];
    if ([[userInfo objectForKey:@"user_id"] isEqualToString:[info objectForKey:@"user_id"]]) {
        [usernameArray addObject:[userInfo objectForKey:@"username"]];
    }
}
NSDictionary*info=[json-objectAtIndex:indexath.row];
NSDictionary*用户信息;

对于(int i=0;i您需要首先添加以下内容:

usernameArray = [[NSMutableArray alloc]init];
然后将循环更改为以下内容:

NSDictionary *info = [json objectAtIndex:indexPath.row];
NSDictionary *userInfo;
for (int i=0; i<[userArray count]; i++) {
    userInfo = [userArray objectAtIndex:i];
    if ([[userInfo objectForKey:@"user_id"] isEqualToString:[info objectForKey:@"user_id"]]) {
        [usernameArray addObject:[userInfo objectForKey:@"username"]];
    }
}
NSDictionary*info=[json-objectAtIndex:indexath.row];
NSDictionary*用户信息;

对于(int i=0;iMy的第一个问题是,您有这行代码吗?usernameArray=[[NSMutableArray alloc]init];没有。@Ryan Tobin我的第一个问题是,您有这行代码吗?usernameArray=[[NSMutableArray alloc]init];没有。@Ryan Tobin