您的位置:首页 > 移动开发 > Cocos引擎

Json文件解析cocos

2016-01-25 23:54 501 查看
std::string str = FileUtils::getInstance()->getStringFromFile("config.json");

rapidjson::Document doc;
doc.Parse<0>(str.c_str());

rapidjson::Value& v = doc["init_cfg"];
rapidjson::Value& uploadPort = v["uploadPort"];

CCLOG("uploadPort = %d", uploadPort.GetInt());

rapidjson::Value& simulator_screen_size = doc["simulator_screen_size"];
#if 0
enum Type {
kNullType = 0,		//!< null
kFalseType = 1,		//!< false
kTrueType = 2,		//!< true
kObjectType = 3,	//!< object
kArrayType = 4,		//!< array
kStringType = 5,	//!< string
kNumberType = 6,	//!< number
};
#endif
rapidjson::Type type = simulator_screen_size.GetType();
CCLOG("type is %d", (int)type);
rapidjson::Value& simulator_screen_size_0 = simulator_screen_size[(unsigned int)0];
rapidjson::Value& title = simulator_screen_size_0["title"];
CCLOG("title=%s", title.GetString());

// 写文件
rapidjson::StringBuffer buf;
rapidjson::Writer<rapidjson::StringBuffer> w(buf);
doc.Accept(w);

buf.GetString();
buf.Size();

FILE* file = fopen("d:\\test.json.txt", "wt");
fwrite(buf.GetString(), buf.Size(), 1, file);
fclose(file);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: