How to read data from plist

How to read data from plist
0.0 0


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;
CCObject* name=screenSounds~~>objectForKey;
const char

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 (0.6 KB)


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

Check out 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”);
int x=files~~>count;
cocos2d::CCObject * lists= files~~>objectAtIndex;
const char** list1=((cocos2d::CCString**))>getCString;
cocos2d::CCObject* name=screenSounds
const char** name1=((cocos2d::CCString *)(name))>getCString;


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();



code is working for me only i changed
const char * key = files~~>objectAtIndex~~>getCString;
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)


Better to use traversal, based on the wiki: [[]]

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;
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