cocos2dx 2.2.2 cocostudio 数据编辑器导出的.json文件读取 解析

首先,创建


然后

再导出数据:

再然后,可以看到数据的格式是:

再然后,就是

数据解析代码:

//

rapidjson::Document _doc;
    bool bRet = false;
    unsigned long size = 0;
    unsigned char *pBytes = NULL;
    do {
        pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData("Book1.json", "r", &size);
        CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0);
        std::string load_str((const char*)pBytes, size);
        CC_SAFE_DELETE_ARRAY(pBytes);


        _doc.Parse<0>(load_str.c_str());


        CC_BREAK_IF(_doc.HasParseError());
        //CCLOG("helloworld:%d", DICTOOL->getIntValue_json(_doc, "layer"));
        //DICTOOL->getIntValue_json(_doc, "layer");
        //auto temp = _doc["row0"].GetString();
        //DICTOOL->getDictionaryFromArray_json(_doc,"layer",1);

        
        
        CC_BREAK_IF(!_doc.IsArray());

        


            CCLOG("ffff:%d",_doc.GetType());
            for (rapidjson::SizeType i = 0; i < _doc.Size(); i++)
            {
                const rapidjson::Value &p = _doc[i];
                /在这里写下你处理语句
                CCLOG("rrrr:%d", p["row2"].GetInt());
                
            }



        bRet = true;
    } while (0);

//


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值