how to initialize CCArray with the elements of CCDictionary?

hello,I’m a rookie and I’m learning cocos2d-x recently.I want to initialize an array with the elements of dictionary like these code.But xcode sends an error that I using invalid parameter to initialize CCArray. Who can help me to recompose it? thank you!

const char path = CCFileUtils::sharedFileUtils->fullPathFromRelativeFile;
CCDictionary
manifest = CCDictionary::createWithContentsOfFile(path);
CCArray spritesheets = CCArray::createWithObject);
CCArray
images = CCArray::createWithObject(manifest->objectForKey(“Images”));
CCArray soundFX = CCArray::createWithObject);
CCArray
music = CCArray::createWithObject(manifest->objectForKey(“Music”));
CCArray assets = CCArray::createWithObject);
I write the code referencing a cocos2d-iphone example.The original code is written by objective-C:
NSString
path = [[CCFileUtils sharedFileUtils] fullPathFromRelativePath: "preloadAssetManifest.plist"]; NSDictionary *manifest = [NSDictionary dictionaryWithContentsOfFile:path]; NSArray *spriteSheets = [manifest objectForKey:“SpriteSheets”];
NSArray images = ;
NSArray
soundFX = [manifest objectForKey: "SoundFX"]; NSArray *music = [manifest objectForKey:“Music”];
NSArray *assets = [manifest objectForKey: @“Assets”];

CCDictionary *manifest = CCDictionary::createWithContentsOfFile(path);
change path to "preloadAssertManifest.plist".

if you need const char *path. use fullPathForFilename is a better choice.
std::string pt = CCFileUtils::sharedFileUtils()->fullPathForFilename("preloadAssertManifest.plist");

CCArray *images = CCArray::createWithObject(manifest->objectForKey("Images"));
here, if you know you will get a CCArray, use createWithArray is a better choice.
CCArray *images = CCArray::createWithArray((CCArray*)manifest->objectForKey("Images"));

gook luck.

shujun qiao wrote:

[…]
if you need const char *path. use fullPathForFilename is a better choice.
std::string pt = CCFileUtils::sharedFileUtils()->fullPathForFilename("preloadAssertManifest.plist");
>
CCArray *images = CCArray::createWithObject(manifest->objectForKey("Images"));
here, if you know you will get a CCArray, use createWithArray is a better choice.
CCArray *images = CCArray::createWithArray((CCArray*)manifest->objectForKey("Images"));
>
gook luck.

Hi qiao,thank you very much.I replaced the code as your answer,but the error is also existing.It says that the parameter “manifest->objectForKey(”Images“)” is invalid.
The array which get by the method of objecForKey maybe an empty array.
But also thanks for your help.

hi.
did you use this line?

CCArray *images = CCArray::createWithArray((CCArray*)manifest->objectForKey("Images"));

I think the question for “the parameter … is invalid.” is you missed (CCArray**).
it does use CCObject** force to CCArray*.then we can use CCArray::createWithArray.

shujun qiao wrote:

hi.
did you use this line?
[…]
I think the question for “the parameter … is invalid.” is you missed (CCArray**).
it does use CCObject** force to CCArray*.then we can use CCArray::createWithArray.

Yeah,I use that line.But the project exited when createWithArray was invoked,like this:

i test this code in Xcode.

CCDictionary *manifest = CCDictionary::createWithContentsOfFile("preloadAssertManifest.plist");
    CCLog("dictory: %d.", manifest->count());
    CCArray* spritesheets = CCArray::createWithArray((CCArray*)manifest->objectForKey("SpriteSheets"));
    CCLog("spritesheets: %d.", spritesheets->count());
    CCArray* images = CCArray::createWithArray((CCArray*)manifest->objectForKey("Images"));
    CCLog("images: %d.", images->count());    
    for (int i=0; icount(); i++) {
        CCObject* obj = images->objectAtIndex(i);
        CCString* str = (CCString*)(obj);
        CCLog("%d: %s", i, str->getCString());
    }

and it’s correct.
print:

Cocos2d: dictory: 5.
Cocos2d: spritesheets: 2.
Cocos2d: images: 3. first: ad2d940
Cocos2d: 0: 123
Cocos2d: 1: qwe
Cocos2d: 2: asf

i didn’t know the struct of your “preloadAssertManifest.plist”.
so i create a plist.
can you show me your plist?

shujun qiao wrote:

i test this code in Xcode.
[…]
and it’s correct.
print:
[…]
>
i didn’t know the struct of your “preloadAssertManifest.plist”.
so i create a plist.
can you show me your plist?

ok,thank you,qiao.
I found the matter just now. My “.plist” file is error.
Now,it’s ok.
Thank you very much!