0

这是代码:

NSMutableDictionary *circuit_step = [NSMutableDictionary dictionary];    
NSMutableDictionary *step_info    = [NSMutableDictionary dictionary];

 [step_info setObject: @"search"   forKey: @"search-type"];     
 [step_info setObject: @"small"   forKey: @"search-format"];     
 [step_info setObject: @"winter"   forKey: @"search-season"];    
 [step_info setObject: @"tree"   forKey: @"search-location"];

 **[circuit_step setObject: circuit_step forKey: @"01"];**

 [step_info setObject: @"search"   forKey: @"search-type"]; 
 [step_info setObject: @"micro"   forKey: @"search-format"];     
 [step_info setObject: @"summer"   forKey: @"search-season"];    
 [step_info setObject: @"by the lake"          forKey: @"search-location"];

 **[circuit_step setObject: circuit_step forKey: @"02"];**

以适合 NSLog 的格式直接访问的代码是什么dictionary circuit_step key "01"dictionary step_info key "search-location"

4

1 回答 1

1

关于什么

NSLog(@"Value is %@",
    [[circuit_step objectForKey: @"01"] objectForKey: @"search-location"])

另外,您的代码全错了。这是一个固定版本:

NSMutableDictionary *circuit_step = [NSMutableDictionary dictionary];
if (circuit_step != nil)
{
    NSMutableDictionary* step_info = nil;

    step_info = [NSMutableDictionary dictionary];
    if (step_info != nil) {
        [step_info setObject: @"search" forKey: @"search-type"];
        [step_info setObject: @"small" forKey: @"search-format"];
        [step_info setObject: @"winter" forKey: @"search-season"];
        [step_info setObject: @"tree" forKey: @"search-location"];
        [circuit_step setObject: step_info forKey: @"01"];
    }

    step_info = [NSMutableDictionary dictionary];
    if (step_info != nil) {     
        [step_info setObject: @"search" forKey: @"search-type"];
        [step_info setObject: @"micro" forKey: @"search-format"];
        [step_info setObject: @"summer" forKey: @"search-season"];
        [step_info setObject: @"by the lake" forKey: @"search-location"];
        [circuit_step setObject: step_info forKey: @"02"];
    }
}

您没有在 circuit_step 中设置正确的对象,并且您还重用了一个字典,因此您最终会得到两个条目,它们指向同一个字典,其值为“02”。

于 2010-02-03T15:51:24.680 回答