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

首先,创建


然后

再导出数据:

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

再然后,就是

数据解析代码:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //  
  2.   
  3. rapidjson::Document _doc;  
  4.     bool bRet = false;  
  5.     unsigned long size = 0;  
  6.     unsigned char *pBytes = NULL;  
  7.     do {  
  8.         pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData("Book1.json""r", &size);  
  9.         CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0);  
  10.         std::string load_str((const char*)pBytes, size);  
  11.         CC_SAFE_DELETE_ARRAY(pBytes);  
  12.   
  13.   
  14.         _doc.Parse<0>(load_str.c_str());  
  15.   
  16.   
  17.         CC_BREAK_IF(_doc.HasParseError());  
  18.         //CCLOG("helloworld:%d", DICTOOL->getIntValue_json(_doc, "layer"));  
  19.         //DICTOOL->getIntValue_json(_doc, "layer");  
  20.         //auto temp = _doc["row0"].GetString();  
  21.         //DICTOOL->getDictionaryFromArray_json(_doc,"layer",1);  
  22.   
  23.           
  24.           
  25.         CC_BREAK_IF(!_doc.IsArray());  
  26.   
  27.           
  28.   
  29.   
  30.             CCLOG("ffff:%d",_doc.GetType());  
  31.             for (rapidjson::SizeType i = 0; i < _doc.Size(); i++)  
  32.             {  
  33.                 const rapidjson::Value &p = _doc[i];  
  34.                 /在这里写下你处理语句  
  35.                 CCLOG("rrrr:%d", p["row2"].GetInt());  
  36.                   
  37.             }  
  38.   
  39.   
  40.   
  41.         bRet = true;  
  42.     } while (0);  
  43.   
  44. //  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值