参考这个方法读取
bool CCComAttribute::parse(const std::string &jsonPath)
{
bool bRet = false;
unsigned long size = 0;
unsigned char pBytes = NULL;
do {
pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(jsonPath.c_str(), “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());////////////////////////////_doc.Parse这一个函数是解析方法,解析后,其中_doc是 rapidjson::Document _doc;类型的一个全局变量
CC_BREAK_IF(_doc.HasParseError());
bRet = true;
} while (0);
return bRet;
}
解析后可以通过调用
DICTOOL->getStringValue_json(_doc, key);//_doc是存放解析后数据的对象。key是你想要获取到的内容的关键字
DICTOOL->getBooleanValue_json(_doc, key);
DICTOOL->getFloatValue_json(_doc, key);
…
等方法获取值。