要被解析遍历的json(存放在BaccaratBettingBoard.json文件中):
{ "1001":[271,3,536,171],"1002":[3,269,"1003":[173,173,357,297],"1006":[360,"1007":[3,171,297] }
解析代码:
std::string load_str; load_str = FileUtils::getInstance()->getStringFromFile("BaccaratBettingBoard.json"); rapidjson::Document readdoc; readdoc.Parse<0>(load_str.c_str()); if(readdoc.HasParseError()) { log("GetParseError%s\n",readdoc.GetParseError()); } CCASSERT(readdoc.IsObject(),"bettingBoard::initBettingBoard: 读取json失败,无法初始化下注区!"); for(auto iter = readdoc.MemberonBegin(); iter != readdoc.MemberonEnd(); ++iter) { auto key = (iter->name).GetString(); log("key:%s",key); log("value:"); //auto& v = readdoc[key] for(auto i = 0; i < readdoc[key].Size(); ++i) { log("%0.2f",readdoc[key][i].GetDouble()); } }
结果:
原文链接:https://www.f2er.com/json/289848.html