Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d x 无法分析Cocos2dx 3.0中的plist_Cocos2d X_Cocos2d X 3.0 - Fatal编程技术网

Cocos2d x 无法分析Cocos2dx 3.0中的plist

Cocos2d x 无法分析Cocos2dx 3.0中的plist,cocos2d-x,cocos2d-x-3.0,Cocos2d X,Cocos2d X 3.0,我想解析这个plist结构…请帮助 我现在用的是 mainDictionary = __Dictionary::createWithContentsOfFile(plistPath.c_str()); __Dictionary *exit = (__Dictionary*)__Dictionary::createWithDictionary( (__Dictionary*)mainDictionary->objectForKey(std::string("other

我想解析这个plist结构…请帮助

我现在用的是

mainDictionary = __Dictionary::createWithContentsOfFile(plistPath.c_str());
__Dictionary *exit = (__Dictionary*)__Dictionary::createWithDictionary(
            (__Dictionary*)mainDictionary->objectForKey(std::string("otherButton")));

但是有一些键缺少exit dictionanry…

在plist的根目录中根本没有名为“ExitButton”的键(因此在
主字典中)

mainDictionary
键将是“background”、“otherButton”和“Buttons”,每个键都返回另一个字典或数组实例


如果“ExitButton”键位于Buttons数组中的某个位置,则必须枚举Buttons数组并在其中一个数组项中找到“ExitButton”键。

尝试使用ValueMap和FileUtils加载PList文件。您尝试从cocos2d-xv2.x加载字典的方式。在cocos2d-x中,您应该执行以下操作:

ValueMap mainDictionary = FileUtils::getInstance()->getValueMapFromFile(plistPath.c_str());

ValueMap exit = mainDictionary["otherButton"].asValueMap();

在3.0+版本中,不推荐使用CCDictionary CCArray之类的数据结构。您必须使用ValueMapValueVector等 您可以在文件夹ValueVector>CCValue.h

以下是阅读此plist的代码:

cocos2d::ValueMap gameData;
gameData = FileUtils::getInstance()->getValueMapFromFile("data.plist");
如果要读取值,请执行以下操作:

//1
std::string backgroundValue = gameData.at("background");

//2
ValueMap otherButtonsMap = gameData.at("otherButton").asValueMap();
std::string tagValue = otherButtonsMap.at("Tag");

//3
ValueVector buttonsVector = gameData.at("Buttons").asValueVector();
ValueMap item0 = buttonsVector.at(0).asValueMap();
其中游戏数据是ValueMap(或者换句话说,Dictionary、Map或HashMap)

编辑:


“Wez Sie Tato”的回答是正确的,但在您的案例中,您应该阅读ValueMap中的plist而不是ValueVector,因为您的plist实际上是字典(ValueMap),而不是数组(ValueVector)。

我已经编辑了这个问题。我知道你在说什么,但我需要语法,因为我是UIKit的iOS开发人员。由于我解析dictionary,它只给出了一个键,尽管对于类型'ValueVector'(也称为'vector')没有可行的重载运算符[]得到了这个错误&对于maindctionary,它的给定大小=0I,我在使用ValueVector:)的项目中复制这行时出错,现在一切正常。