• 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 = (__String*)loadDictInDict->objectForKey("bool");
            CCLOG("%s",boolValue->getCString());
            auto floatValue = (__String*)loadDictInDict->objectForKey("float");
            CCLOG("%s",floatValue->getCString());
            auto intValue = (__String*)loadDictInDict->objectForKey("integer");
            CCLOG("%s",intValue->getCString());
            auto doubleValue = (__String*)loadDictInDict->objectForKey("double");
            CCLOG("%s",doubleValue->getCString());
    


  • 相关阅读:
    2018-2019-2 网络对抗技术 20165206 Exp3 免杀原理与实践
    2018-2019-2 网络对抗技术 20165206 Exp2 后门原理与实践
    2018-2019-2 20165206《网络对抗技术》Exp1 PC平台逆向破解
    css常见布局之三列布局--双飞翼布局和圣杯布局
    css常用布局
    基础总结(05)-- 回流和重绘
    基础总结(04)-- display:none;&&visibility:hidden;区别
    js实现点击按钮复制文本功能
    基础总结(03)-- css有趣的特性
    基础总结(02)--BFC(块级格式化上下文)
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/6704221.html
Copyright © 2020-2023  润新知