我有一个NSDictonary对象,我将一组对象设置为一个具有相应键的数组,如下所示。
[dictionary setObject: [NSArray arrayWithObjects:@"Player3_Title", @"FirstName", @"LastName", @"Address3", @"SS3", nil] forKey: @"player3_infoKey"];
我想要做的是将这些对象放回到数组中。当我尝试以下代码时,这就是我得到的输出。
stringsMutableArray = [[NSMutableArray alloc] initWithObjects:nil];
[stringsMutableArray addObject:[dictionary objectForKey:@"player3_infoKey"]];
NSLog(@"stringsMutableArray has values: %d", [stringsMutableArray count]);
NSLog(@"stringMutableArray: %@", [stringsMutableArray objectAtIndex:0]);
OUTPUT:
2012-01-01 08:50:29.869 test project[1165:f803] stringsMutableArray has values: 1
2012-01-01 08:50:29.870 test project[1165:f803] stringMutableArray: (
"Player3_Title",
FirstName,
LastName,
Address3,
SS3
)
有没有办法可以将该密钥的值转换为数组?我想这样做的原因是我想在代码中的某个地方设置该数组的文本按钮值。
FirstNameField1.text = [stringsMutableArray objectAtIndex:1];
LastNameField1.text = [stringsMutableArray objectAtIndex:2];
答案 0 :(得分:1)
我想你只想:
stringsMutableArray = [NSMutableArray arrayWithArray:[dictionary objectForKey:@"player3_infoKey"]];
如果你不需要它是可变的:
stringsArray = [dictionary objectForKey:@"player3_infoKey"];
答案 1 :(得分:0)
NSArray *myArray = [dictionary objectForKey:@"player3_infoKey"];
[myArray objectAtIndex:0]; // Should return "Player3_Title"