1

I have an array that looks like this:

 {
    name = Size;
    "option_id" = 13;
    "product_option_id" = 380;
    required = 1;
    type = select;
}     

and when i log an output like so:

NSLog(@"productOptions %@",[self.singleProductOptionsArray valueForKey:@"name"]);

it outputs the result inside an array so i cannout put it into a string:

 2013-08-01 11:10:33.116 vinylsdirect[210:907] productOptions (
 Size
)

i am using the same code in other arrays and everything is working fine so im not sure what is going on. i have also tried changing the NSLog like so:

NSLog(@"productOptions %@",[[self.singleProductOptionsArray objectAtIndex:0] valueForKey:@"name"]); 

Does anyone have any idea what might be causing my issues?

Thanks

4

2 回答 2

2

我认为它是一个nsarray包含nsdictionarys. 迭代它。看看这是否有效?

for (NSDictionary *prod in self.singleProductOptionsArray)
{
    NSLog(@"Prod: %@", [prod valueForKey:@"name"]);
}
于 2013-08-01T10:28:11.107 回答
0

当调用valueForKey:一个NSArray定义的返回值是一个数组,其中包含在每个数组对象上调用valueForKey:using的结果。key因此,您所看到的正是您所要求的。

准确检查您拥有哪些类型的对象以及嵌套是什么。

于 2013-08-01T10:30:31.717 回答