How to read data from plist

hi,
in my project i am trying to load sound file from plist

but i am not getting how to read the strings from plist

i tried like this

method 1:

cocos2d::CCDictionary * plistDictionary=cocos2d::CCDictionary::createWithContentsOfFile(fileName1.c_str());

cocos2d::CCArray * items=(cocos2d::CCArray )plistDictionary~~>objectForKey;
int n_entities=items~~>count;
but here items~~>count is showing some random value, it should give value 19.
method 2:
cocos2d::CCDictionary * plistDictionary=cocos2d::CCDictionary::createWithContentsOfFile);
cocos2d::CCDictionary * screenSounds=plistDictionary~~>objectForKey;
//screenSounds~~>count;
CCObject* name=screenSounds~~>objectForKey;
const char
name1=((cocos2d::CCString*)(name))->getCString();

in this method every have to give “keyValue” (objectForKey(“”)).
is there any method to load all sound files with out giving object key

can any one help me read data(strings) from plist


SoundEffects.plist.zip (0.6 KB)

As the value for AllSounds is a dict you should use method 2.

Check out http://www.cocos2d-x.org/embedded/cocos2d-x/d7/d5f/classcocos2d_1_1_c_c_dictionary.html for the functions of CCDictionary.

You can get a array of all the keys and then loop round getting the value for the key.

thanks @ Adam Reed
your suggestion helped to read plist files
working code:
cocos2d::CCDictionary * plistDictionary=cocos2d::CCDictionary::createWithContentsOfFile(“SoundEffects.plist”);
screenSounds=(cocos2d::CCDictionary**)plistDictionary~~>objectForKey;
files=screenSounds~~>allKeys;
int x=files~~>count;
for;i++)
{
cocos2d::CCObject * lists= files~~>objectAtIndex;
const char** list1=((cocos2d::CCString**))>getCString;
cocos2d::CCObject* name=screenSounds
>objectForKey;
const char** name1=((cocos2d::CCString *)(name))>getCString;
sound
>sharedEngine()->preloadEffect(name1);
}

I’m not if this code below would work for you?

    CCDictionary * plistDictionary = CCDictionary::createWithContentsOfFile("SoundEffects.plist");
    screenSounds = (CCDictionary*)plistDictionary->objectForKey(soundGroup); 
    files = (CCArray*)screenSounds->allKeys(); 

    for(unsigned int i = 0; i < files->count(); i++) {
        const char * key = files->objectAtIndex(i)->getCString(); 
        const char * effectName = screenSounds->valueForKey(key)->getCString();

        sound->sharedEngine()->preloadEffect(effectName);
    }

code is working for me only i changed
const char * key = files~~>objectAtIndex~~>getCString;
to
const char * key = files~~>objectAtIndex)~~>getCString();

CCDictionary * plistDictionary = CCDictionary::createWithContentsOfFile(“SoundEffects.plist”);
screenSounds = (CCDictionary**)plistDictionary~~>objectForKey;
files = screenSounds~~>allKeys;
>
for; i++) {
const char** key =((cocos2d::CCString**) files~~>objectAtIndex)>getCString;
const char** effectName = screenSounds->valueForKey(key)
>getCString;
>
sound~~>sharedEngine()->preloadEffect(effectName);
}

Better to use traversal, based on the wiki: [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/API_Change_List_from_v1x_to_2x]]

CCDictElement* pElement = NULL;
CCDICT_FOREACH(theDict, pElement)
{
    CCObjectSubClass* pSubClassObj = (CCObjectSubClass*)pElement->getObject();
    // You can also get the current key, but make sure you know the key type.
    std::string oneStrKey = pElement->getStrKey(); // if the key type is string.
    // int oneIntKey = pElement->getIntKey(); // if the key type is integer.
    // do some operation by using pSubClass pointer.
    ...
{

sandeep g wrote:

code is working for me only i changed
const char * key = files~~>objectAtIndex~~>getCString;
to
const char * key = files~~>objectAtIndex)~~>getCString();

I see, convert files~~>objectAtIndex to cocos2d::CCString* before calling~~>getCString().

We have created a PLIST video tutorial series PLIST Video Tutorial