Reading CCArray from CCDictionary?

Reading CCArray from CCDictionary?
0.0 0


I have been using CCDictionary for a while to read in various strings and values like so:

const char *path = CCFileUtils::fullPathFromRelativePath;
CCDictionary<string, CCObject
>dictionary = CCFileUtils::dictionaryWithContentsOfFile(path);
CCDictionary<string, CCObject
> *miniDict = (CCDictionary<string, CCObject
int somethingInteger = miniDict~~>objectForKey(“something”))->toInt();

However, I am stumped trying to read in an “Array”? I have an “Array” of dictionaries each with their own sub arrays, etc, and need to read it into a CCArray. Suggestions?


Please try:

CCDictionary *dictionary = CCFileUtils::dictionaryWithContentsOfFile(path);
CCDictionary *miniDict = (CCDictionary*)( dictionary->objectForKey("someDictionary") );


Sorry, I had a typo in my original code and was missing the > that you put back in :slight_smile: . The correct syntax is in my live code, I just messed up the copy/paste to the forum. Although that was not my question, I guess I wasnt overly clear as to what my question actually was… I am attempting to read a Plist into some values within Cocos2d-x. I can open the Plist dictionary and sub dictionaries using the code you posted above, but I cannot for the life of me figure out how to read a Plist “Array” value into a Cocos2d-x array/dictionary container in order to parse their data further.

I have tried to read the arrays as dictionaries but that causes a fault. However, if I manually go into the Plist in XCode and simply set all arrays as dictionaries, I can read them fine. However I really dont want to have to do that for all the Plists I am using that contain arrays. Is there a way to cast or convert a PList array to a dictionary as it is being read in by Cocos2d-x?

Sorry for the confusion, and the typos (Thats what I get for using a global copy paste!). :wink:


I am still having massive issues getting this to work… :frowning:
Here is what I think it “should” look like, but this does not work…

const char *path = CCFileUtils::fullPathFromRelativePath(pszPlist);
CCDictionary *dictionary = CCFileUtils::dictionaryWithContentsOfFile(path);
CCArray* array = (CCArray*)dictionary->objectForKey("arrayOfDictionaries");


Sorry for the “edits” I messed up the pre formating.



I got some problem when try to read CCArray from plist ,
when I use

CCArray* array = (CCArray*)dictionary->objectForKey(“arrayOfDictionaries”);
CCLog(“count : %d”,array->count());

I got a random number from the log

anyone meet the same problem ?

I’m using cocos2d-1.0.1-x-0.12.0, I’ve successfully read string from my plist before