目标C:从字典中获取值

时间:2016-01-28 13:54:34

标签: objective-c dictionary

我的“saveData”字典如下所示:

{
    Adresser =     {
        "completed_status" =         {
            finished = 4;
            total = 5;
        };
    ...
}

我的“dOrder”字典看起来像这样

{
    id = 1924;
    name = Adresser;
    order = 0;
}

代码片段

NSDictionary * saveData = [self dbReadFormData:_objectID];

for (NSDictionary * dOrder in dictFormSections[@"order"]) {

    NSString * segName = dOrder[@"name"];

    NSLog(@"finished: %@", saveData[segName][@"completed_status"][@"finished"]);
    NSLog(@"total: %@", saveData[segName][@"completed_status"][@"total"]);

    NSString * vFinished = [saveData objectForKey:saveData[segName][@"completed_status"][@"finished"]];
    NSString * vTotal = [saveData objectForKey:saveData[segName][@"completed_status"][@"total"]];

    NSString * sSection = [NSString stringWithFormat:@"%@  -  %@ / %@", segName, vFinished, vTotal];
    [rx insertSegmentWithTitle:sSection atIndex:rx.numberOfSegments animated:NO];
}

NSLog返回正确的值。 (4和5)但NSStrings是零。

我做错了什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

如@ Arc676所述,你有:

NSLog(@"finished: %@", saveData[segName][@"completed_status"][@"finished"]);

NSString * vFinished = [saveData objectForKey:saveData[segName][@"completed_status"][@"finished"]];

然而,它们并不相同。 vFinished 不应该像:

NSString* vFinished = saveData[segName][@"completed_status"][@"finished"];