<分区>
我需要以下结果:
(
"some_key" = {
"another_key" = "another_value";
};
);
为此,我有这段代码,但它不起作用:
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"another_value", @"another_key", nil];
NSMutableArray *array = [[NSMutableArray alloc] init];
[array setValue:dictionary forKey:@"some_key"];
有什么想法吗?谢谢!
你的错误在这里:
NSMutableArray *array = [[NSMutableArray alloc] init];
[array setValue:dictionary forKey:@"some_key"];
------------^^^^^
您正在将其设置到数组中。
试试这个:
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"another_value", @"another_key", nil];
NSDictionary *outDict=[[NSDictionary alloc]initWithObjectsAndKeys:dictionary,@"some_key", nil];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:outDict, nil];
在新文字中:
NSDictionary *d=@{@"another_key":@"another_value"};
NSDictionary *c=@{@"some_key":d};
NSArray *array=@[c];
或者嵌套创建:
NSArray *array=@[@{@"some_key":@{@"another_key":@"another_value"}}];