首页 > 代码库 > Cocos2d3.0 制作PList文件
Cocos2d3.0 制作PList文件
auto root = Dictionary::create(); auto string = String::create("string element value"); root->setObject(string, "string element key"); auto array = Array::create(); auto dictInArray = Dictionary::create(); dictInArray->setObject(String::create("string in dictInArray value 0"), "string in dictInArray key 0"); dictInArray->setObject(String::create("string in dictInArray value 1"), "string in dictInArray key 1"); array->addObject(dictInArray); array->addObject(String::create("string in array")); auto arrayInArray = Array::create(); arrayInArray->addObject(String::create("string 0 in arrayInArray")); arrayInArray->addObject(String::create("string 1 in arrayInArray")); array->addObject(arrayInArray); root->setObject(array, "array"); auto dictInDict = Dictionary::create(); dictInDict->setObject(String::create("string in dictInDict value"), "string in dictInDict key"); //add boolean to the plist auto booleanObject = Bool::create(true); dictInDict->setObject(booleanObject, "bool"); //add interger to the plist auto intObject = Integer::create(1024); dictInDict->setObject(intObject, "integer"); //add float to the plist auto floatObject = Float::create(1024.1024f); dictInDict->setObject(floatObject, "float"); //add double to the plist auto doubleObject = Double::create(1024.123); dictInDict->setObject(doubleObject, "double"); root->setObject(dictInDict, "dictInDict, Hello World"); // end with / std::string writablePath = FileUtils::getInstance()->getWritablePath(); std::string fullPath = writablePath + "text.plist"; if(root->writeToFile(fullPath.c_str())) log("see the plist file at %s", fullPath.c_str()); else log("write plist file failed"); auto loadDict = __Dictionary::createWithContentsOfFile(fullPath.c_str()); auto loadDictInDict = (__Dictionary*)loadDict->objectForKey("dictInDict, Hello World"); auto boolValue = http://www.mamicode.com/(__String*)loadDictInDict->objectForKey("bool");>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。