我正在尝试将一个多维数组分配给一个单维数组以用于我的 UITable View 构造。我决定使用循环来节省时间,因为手动添加数组的数据负载非常繁重。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString1 = [[NSString alloc] initWithData:responseData1 encoding:NSUTF8StringEncoding];
NSLog(@"%@",responseString1);
SBJsonParser *parser = [[SBJsonParser alloc] init];
id sample = [parser objectWithString:responseString1];
for (int i = 0; i < [sample count]; i++) {
[tableData addObject:[[sample objectAtIndex:i]objectAtIndex:1]];
NSLog(@"%@",[sample objectAtIndex:i]);
NSLog(@"%@",[tableData objectAtIndex:i]);
}
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
现在“sample”的 NSLog 反射(reflect)数据,但“tableData”的 NSLog 反射(reflect) NULL。
提前致谢
最佳答案
假设tableData
是一个空的NSMutableArray
,只需使用
[tableData addObject:[[sample objectAtIndex:i]objectAtIndex:0]];
如果您确实想更改tableData
而不是构建它,请使用
[tableData replaceObjectAtIndex:i withObject:[[sample objectAtIndex:i]objectAtIndex:0]];
关于ios - 为从服务器加载的数据分配 2 维数组到 1 维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15616781/