我将NSDictionary
个电话号码添加到NSMutableArray
,如下所示:
NSMutableArray *main_level = [NSMutableArray array];
[main_level addObject:@{@"phone":@[@"052443223",@"763765347647",@"763765347647",@"763765347647",@"763765347647",@"763765347647",@"763765347647"]}];
这是日志打印的内容:
2013-10-14 10:49:27.544 tfv[44111:907] (
{
phone = (
052443223,
763765347647,
763765347647,
763765347647,
763765347647,
763765347647,
763765347647
);
}
)
但是预期的结果是没有像这样的大括号:
当我记录这个NSLog(@"%@",[main_level objectAtIndex:0]);
2013-10-14 10:50:22.539 tfv[44129:907] {
phone = (
052443223,
763765347647,
763765347647,
763765347647,
763765347647,
763765347647,
763765347647
);
}
为什么要添加这些括号,我该如何避免呢?
答案 0 :(得分:3)
( <-- beginning of array
{ <-- beginning of dictionary
phone = ( <-- beginning of phone array
052443223,
763765347647,
763765347647,
763765347647,
763765347647,
763765347647,
763765347647
); <-- end of phone array
} <-- end if dictionary
) <-- end of array
这只是意味着你要打印一个数组。即NSLog(@"%@",main_level);
如果您执行NSLog(@"%@",[main_level objectAtIndex:0]);
,那么您正在打印字典。
答案 1 :(得分:2)
1)您正在使用key = phone将一组电话号码添加到字典中。
2)然后你将那个字典添加到数组中。
所以,无论输出是否正确。你只是无法避免那些大括号。
如果您想获得第一个电话号码,请执行此操作,
NSDictionary *dictOfPhoneNumbers = [[main_level objectAtIndex:0] objectForKey:@"phone"];
for(int i=0; i<dictOfPhoneNumbers.count; i++)
{
NSLog(@"Phone = %@",[dictOfPhoneNumbers objectAtIndex:i]);
}