rapidjson 遍历

时间:2015-03-18 10:36:50   收藏:0   阅读:11900

要被解析遍历的json(存放在BaccaratBettingBoard.json文件中):

{
"1001":[271,3,536,171],
"1002":[3,3,269,171],
"1003":[173,173,357,297],
"1006":[360,173,536,297],
"1007":[3,173,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());
        }
    }

         结果:

技术分享

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!