2

次のコードを使用しています。

NSMutableDictionary *farmGatesDict  = [[NSMutableDictionary alloc] 
                 initWithDictionary:[xmlDictionary objectForKey:@"FarmGates"]];

        NSLog(@"value from dictionary : %@", [farmGatesDict objectForKey:@"FarmGate"]);


NSMutableDictionary *farmDetailDict=[[NSMutableDictionary alloc] 
                 initWithDictionary:[farmGatesDict objectForKey:@"FarmGate"]];

NSLog(@"%@", farmGateString);

このディクショナリは解析された xml ファイルであり、ツリーをトラバースしたいため、これを使用しています。私の最初のコードはfarmGatesDictうまく機能しますが、2番目のfarmDetailDictアプリケーションは次の例外でクラッシュします:

-[NSDictionary initWithDictionary:copyItems:]: 辞書引数は NSDictionary ではありません'

私が後ろに欠けていると私に提案してください..

以下はNSLogデータです...

2012-12-28 15:40:05.223 FarmGates[6170:c07] value from dictionary : (
        {
        address =         {
            text = "\n        2873 Huon Highwway, 2km south of Huonville, over the bridge on river side of road.";
        };
        contact =         {
            text = "\n        Contact 03 6264 1474";
        };
        description =         {
            text = "\n        Shed Door Sales. Arguably the longest standing and most popular road side stall in the Huon. Incorporated with a modern apple packing facility and featuring the refrigerated displays this ensures the freshest stock direct from the grower.";
        };
        fruits =         {
            fruit =             (
                                {
                    text = "\n        \n          Cherries";
                },
                                {
                    text = "\n          Apple";
                }
            );
            text = "\n        ";
        };
        id = 1;
        images =         {
            image =             (
                                {
                    text = "\n        \n          a1.jpg";
                },
                                {
                    text = "\n          b1.jpg";
                },
                                {
                    text = "\n          c1.jpg";
                }
            );
            text = "\n        ";
        };
        latitude =         {
            text = "\n        -43.04964";
        };
        longitude =         {
            text = "\n        147.03903";
        };
        name =         {
            text = "\n  \n  \n        Griggs Grower Direct apples and cherries";
        };
        open =         {
            text = "\n        Open daily except Christmas and Boxing Day.";
        };
        region =         {
            text = "\n        Huon Valley";
        };
        services =         {
            service =             {
                text = "\n        \n            NA";
            };
            text = "\n        ";
        };
        text = "\n    ";
    },
)
4

5 に答える 5

3

から簡単にわかるように、配列を取得していNSLogます。

(
        {
        address =         {
            text = "\n        2873 Huon Highwway, 2km south of Huonvil

だからobjectAtIndex:最初に使ってから行くobjectForKey:

NSMutableDictionary *farmDetailDict=[[NSMutableDictionary alloc] initWithDictionary:farmGatesDict[0]];
于 2012-12-28T10:36:08.343 に答える
0

[farmGatesDict objectForKey:@"FarmGate"]NSDictionary を返していないようです。どのタイプか確認してください。

于 2012-12-28T10:07:08.803 に答える
0

クラッシュしている行のに次の行を書くだけです..

NSLog(@"value from dictionary : %@", [farmGatesDict objectForKey:@"FarmGate"]);

NSLogの結果を投稿してください..あなたが得ている値はNSDictionary.

于 2012-12-28T10:07:45.357 に答える
0

の戻り値をチェック

farmGatesDict objectForKey:@"FarmGate"]

試しNSLogてみてください

于 2012-12-28T10:08:24.777 に答える
0

[xmlDictionary objectForKey:@"FarmGates"]返さないとは思えませんNSDictionary

NSMutableDictionary *farmGatesDict  = [[NSMutableDictionary alloc] 
                 initWithDictionary:xmlDictionary];

それは働いているはずです。

于 2012-12-28T10:09:04.447 に答える