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);
Json文件解析cocos
最新推荐文章于 2022-02-17 12:40:28 发布