cocos2d-x JsonBox 例子

#include "JsonBox.h"
std::string path = "test.json”;
//注意引入路径
        path = cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str());       
/*写入文件*/
        JsonBox::Object o;
        o["myName"] = JsonBox::Value(123);
        o["myOtherMember"] = JsonBox::Value("asld\\kfn");
        o["hahaha"] = JsonBox::Value(true);
        o["adamo"] = JsonBox::Value(129.09);
        std::cout << o << std::endl;
        JsonBox::Value v(o);
        v.writeToFile(path);
            
/*读取文件*/
        JsonBox::Value v2;
        v2.loadFromFile(path);
        std::cout << v2 << std::endl;
            
        /*读取json语句*/
        JsonBox::Array a;
        a.push_back(JsonBox::Value("I'm a string..."));
        a.push_back(JsonBox::Value(123));
        std::cout << a << std::endl;


你可能感兴趣的:(代码,cocos2d-x,JsonBox)