2017-05-04 3 views
0

私はプログラミングに新しい、Imは他のディレクトリの中に入れ子になっているディレクトリにアクセスするのに問題があります。任意の提案をいただければ幸いです。入れ子になったplistディレクトリcocos2dxにアクセスするには?

例:私は最初のディレクトリにアクセスするために使用Cocos2dxと Nested Dir

コード:

__String *fileName = __String::create("InventoryData.plist"); 

__Dictionary *dictionary = __Dictionary::createWithContentsOfFile(fileName->getCString()); 

それはそれを見つけることができないので、私は__Dictionary::createWithDirectory("Nested Root")を使用して試してみましたが、それは動作しません。確かに私はそれを見つけることができないように簡単な方法があります。申し訳ありません。

答えて

1

辞書を横断するこのマイクロCCDICT_FOREACH(__dict__, __el__)を使用してください。

__Dictionary *dist=__Dictionary::createWithContentsOfFile("xyz.plist"); 

DictElement *d=nullptr; 
CCDICT_FOREACH(dist, d){ 

    CCLOG("%s",d->getStrKey()); // It will print all key name 

    if(*d->getStrKey()==*"texture"){ //Match with particular Key(here I'm using texture) 

     __Dictionary *nested=(__Dictionary*)d->getObject(); // downcast nested dictionary. 

     // Now you've nested dictionary you can get value or if having nested dictionary iterate again 

     CCLOG("%s",nested->valueForKey("width")->getCString()); 
     CCLOG("%s",nested->valueForKey("height")->getCString()); 

    } 
} 
+0

*「テクスチャ」が何であるか説明できますか?なぜ私はそれを文字列変数に置き換えることができません。 – MinusSign

+0

"texture"は 'const char *'型の文字列リテラルなので、ポインタが指すデータを得るために逆参照します。テクスチャは私の.plistのエントリで、親辞書の内部にある__Dictionaryです。dist – Aryan

+0

2つのエントリの開始文字が同じ場合に問題が発生します。彼らはお互いのアイデアを混同しているようですね? – MinusSign

関連する問題