cocos2d-x中使用rapidjson读取json数据
1、过程
(1)读取文件内容到内存
(2)解析json字符串到Document数据对象中
(3)读取Document数据对象中的字段
2、例子
bool CoreRole::initWithFile(string fileName) { string heroConfig = FileUtils::getInstance()->getStringFromFile(fileName); Document doc; doc.Parse(heroConfig.c_str()); if (doc.IsObject()) { string name = doc["name"].GetString(); setName(name); int type = doc["type"].GetUint(); setType(type); string armaturePath = doc["armaturePath"].GetString(); setArmaturePath(armaturePath); string armatureName = doc["armatureName"].GetString(); setArmatureName(armatureName); string stmPath = doc["stmPath"].GetString(); setSTMPath(stmPath); int move_speed = doc["move_speed"].GetInt(); setMoveSpeed(move_speed); } return true; }