1. 在数据编辑器中导入Excel文件
3. 使用文本编辑器查看Json数据
voidgetJsonFromFile(constchar*fileName,rapidjson::Document&jsonDict) { unsignedchar*pBytes=NULL; std::stringjsonpath; jsonpath=CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName); unsignedlongsize=0; pBytes=CCFileUtils::sharedFileUtils()->getFileData(jsonpath.c_str(),"r",&size); CCData*data=newCCData(pBytes,size); std::stringload_str=std::string((constchar*)data->getBytes(),data->getSize()); CC_SAFE_DELETE(data); jsonDict.Parse<0>(load_str.c_str()); }
rapidjson::DocumentrapidJsonData; getJsonFromFile("data.json",rapidJsonData); for(inti=0;i<4;i++) { constchar*name=DictionaryHelper::shareHelper()->getStringValue_json(rapidJsonData[i],"name"); intlevel=DictionaryHelper::shareHelper()->getIntValue_json(rapidJsonData[i],"level"); inthp=DictionaryHelper::shareHelper()->getIntValue_json(rapidJsonData[i],"hp"); intattack=DictionaryHelper::shareHelper()->getIntValue_json(rapidJsonData[i],"attack"); CCLog("%s,%d,%d",name,level,hp,attack); }
6. 程序运行结果