cocos2d-x 3.0 rapidjson 的写入操作应该注意的细节
2020-12-13 02:57
标签:style class blog code http tar cocos2d-x 3.0 交流群: 367086379 cocos2d-x 3.0 rapidjson 的写入操作应该注意的细节,搜素材,soscw.com cocos2d-x 3.0 rapidjson 的写入操作应该注意的细节 标签:style class blog code http tar 原文地址:http://blog.csdn.net/u010296979/article/details/30984933//获取一个可写入的全路径
auto path =FileUtils::getInstance()->getWritablePath();
log("%s", path.c_str());
//在这个路径下添加一个json文件
path.append("myhero.json");
rapidjson::Document document;
document.SetObject();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
rapidjson::Value array(rapidjson::kArrayType);
rapidjson::Value object(rapidjson::kObjectType);
object.AddMember("id", 1, allocator);
object.AddMember("name", "豹儿", allocator);
object.AddMember("age", "3年", allocator);
object.AddMember("low", true, allocator);
array.PushBack(object, allocator);
document.AddMember("propety", "PLAYER-TO", allocator);
document.AddMember("player", array, allocator);
rapidjson::StringBuffer buffer;
rapidjson::Writer<:stringbuffer> writer(buffer);
document.Accept(writer);
FILE* file = fopen(path.c_str(), "wb");
if (file)
{
fputs(buffer.GetString(), file);
fclose(file);
}
头文件要加上以下内容:#include "json/document.h"
#include "json/writer.h"
#include "json/stringbuffer.h"
using namespace rapidjson;
以下是生成效果:
上一篇:js实现全选功能
下一篇:jquery tag页签切换
文章标题:cocos2d-x 3.0 rapidjson 的写入操作应该注意的细节
文章链接:http://soscw.com/essay/26650.html