Ios 向NSMutableArray添加多个对象
我有以下迭代:Ios 向NSMutableArray添加多个对象,ios,Ios,我有以下迭代: historialServicios = [[NSMutableDictionary alloc]init]; // Parse and loop through the JSON for (dictionary in messageArray) { //datos de nivel objects NSString * code = [dictionary objectForKey:@"code"]; NSString * date = [dictio
historialServicios = [[NSMutableDictionary alloc]init];
// Parse and loop through the JSON
for (dictionary in messageArray) {
//datos de nivel objects
NSString * code = [dictionary objectForKey:@"code"];
NSString * date = [dictionary objectForKey:@"date"];
//datos de nivel client
NSDictionary *level2Dict = [dictionary objectForKey:@"client"];
id someObject = [level2Dict objectForKey:@"email"];
NSLog(@"NOMBRE===%@",someObject);
NSString * email = someObject;
NSLog(@"EMAIL=%@",email);
NSLog(@"CODE=%@",code);
NSLog(@"DATE=%@",date);
//insertamos objetos en diccionario historialServicios
}
迭代在json树的根节点内循环,也在子节点“客户机”内循环
我需要的是创建一个NSMutableArray字典。每个字典必须包含从每次迭代中检索到的对象,在这种情况下,键是代码、数据和电子邮件。来自根节点的代码和数据,以及来自子节点的电子邮件
下面的示例中,每个字典都应该是一个包含键和值的对象:
关键值
代码字符串代码
日期字符串日期
电子邮件字符串电子邮件
如何以这种方式创建NSMutableArray?试试:
historialServicios = [[NSMutableDictionary alloc]init];
array = [NSMutableArray new];
// Parse and loop through the JSON
for (dictionary in messageArray) {
//datos de nivel objects
NSString * code = [dictionary objectForKey:@"code"];
NSString * date = [dictionary objectForKey:@"date"];
//datos de nivel client
NSDictionary *level2Dict = [dictionary objectForKey:@"client"];
id someObject = [level2Dict objectForKey:@"email"];
// ADDING TO ARRAY
[array addObject:@{@"code": code, @"date": date, @"email":someObject}];
NSLog(@"NOMBRE===%@",someObject);
NSString * email = someObject;
NSLog(@"EMAIL=%@",email);
NSLog(@"CODE=%@",code);
NSLog(@"DATE=%@",date);
//insertamos objetos en diccionario historialServicios
}