zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

2023-09-27 14:25:13 时间

首先,创建


然后

再导出数据:

再然后,能够看到数据的格式是:

再然后,就是

数据解析代码:

  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. //////////////////