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' の同じディクショナリを指す 2 つのエントリができてしまいます。

于 2010-02-03T15:51:24.680 に答える