码迷,mamicode.com
首页 > Windows程序 > 详细

rapidjson 遍历

时间:2015-03-18 10:36:50      阅读:11900      评论:0      收藏:0      [点我收藏+]

标签:rapidjson   cocos2dx   c++   遍历   json   

要被解析遍历的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());
        }
    }

         结果:

技术分享

rapidjson 遍历

标签:rapidjson   cocos2dx   c++   遍历   json   

原文地址:http://blog.csdn.net/benthy2/article/details/44404951

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!