Plist loading

Plist loading
0.0 0


With cocos2d-x version 0.12 I am trying to load a very simple plist:

key “items” is NSArray

I load it in this way:

@ const char pszPath = CCFileUtils::fullPathFromRelativePath;
CCDictionary<std::string, CCObject
* dictionary = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
CCArray *items = (CCArray *) dictionary~~>objectForKey;
int n_entities = items~~>count();
CCLog(“Count of entities: %d”,n_entities);

I get a random number as response.

I have tried to debug without success.

Can you help me?

Thank you!. (0.4 KB)


Are you sure that the path is ok?

i Haven’t worked yet with arrays in .plist files, first try with a simple .plist with a number for key instead of dictionary. Then, debug it like this:

number = ((CCString *)this~~>_dictionary~~>objectForKey(“number”))->toInt();
CCLog(“The number is %d”,number);

That way you make sure that parsing simple numbers works.

What i do to have dictionary items is to place them in another file referenced by a key in the main .plist file with the path of the file.


I have used the debugger yesterday for 3 hours trying to load an array with just 3 strings in it. The file loads through a IOS method.

Cocos then maps the NSDictionary to CCDictionary all the structure in a recursive mode.

It’s hard to follow the recursive visit which jumps forth and back however I didn’t see any evidend error.

CCDictionary uses C++ stdlib to map all the data structures.

All seams right but when I extract the array with

CCArray *items = (CCArray *) dictionary~~>objectForKey;
and then
int n_entities = items~~>count();

I get a meaningless number while I should have 3.

However your proposal to have arrays stored in files might be a good strategy.

I guess that the plist file format wastes much disk space (the file is 152kb right now and it should be much smaller).

So perhaps I’m dropping the plist technique and try to create a binary file.

Do you know what class can I use to load binary data? have you experienced this?

The problem is that I’m exporting data from a java application (which I created as a level editor) to a binary file which should be imported by the cocos app.

I’m curious to see the final dimensions of the data.


Sorry but i haven’t worked with binary data so far, i really hioe that you can solve your problem. Try the approach that i gave to you, maybe it is more simple than find the answer to your current problem.


why don’t you use a sqlite db?

Maybe is better for your data representation.


Loading data from a PLIST file PLIST Video Tutorial