从NSDictionary获取对象时遇到麻烦

时间:2013-03-08 08:00:48

标签: iphone ios

我正在制作带有2个数组的字典,用于键(你可以在Dic中看到的ID)和一个用于值的数据(你可以在Dic中看到的出生日期)我的字典看起来像这样

100000297621293 = "08/31/1990";
100001904155266 = "12/30/1990";
100003248631105 = "05/27/1990";
100004327360299 = "01/01/1927";
100000157646688 = "08/22/1989";
100001069796883 = "12/03/1989";
100001475514001 = "03/09/1990";
100000717474427 = "08/05/1990";
100001221367192 = "08/05/1990";
100002586744158 = "04/15/1983";

这只是示例dic not full

然后我有另一个带有id的数组,我使用该数组从这个Dic获取出生日期但是我得到空值plz帮助我我的代码如下

注意:我使用钥匙的阵列,总是作为DIC的钥匙存在

NSDictionary *birthdayDictionary = 
[[NSDictionary alloc] initWithObjects:_parssedArrayOfFaceBook forKeys:_parssedArrayOfFaceBookUid];

NSLog(@"asdas%@",birthdayDictionary.description);

NSMutableArray *matches = [NSMutableArray array];

for (NSString *key in _selecteduid) {
    NSLog(@" see it%@",key);
    NSString *selectedBirthDate = [birthdayDictionary objectForKey:key];
    NSLog(@" matched%@",selectedBirthDate);
    [matches addObject:selectedBirthDate];
    NSLog(@" matched%@",matches);

}

2 个答案:

答案 0 :(得分:0)

假设selecteduid是一个保留属性并且其中包含值,则此代码可以正常工作。

NSDictionary *birthdayDictionary = [NSDictionary dictionaryWithObjects:self.parssedArrayOfFaceBook
                                                                   forKeys:self.parssedArrayOfFaceBookUid];
    NSMutableArray *matches = [@[] mutableCopy];

    for (NSString *key in self.selecteduid){
        NSString *selectedBirthDate = birthdayDictionary[key];
        [matches addObject:selectedBirthDate];
    }

答案 1 :(得分:0)

为什么*selectedBirthDateNSMutableArray?出生日期(值)是字符串!不是阵列!

NSString *selectedBirthDate = [birthdayDictionary objectForKey:key];