1. 在数据编辑器中导入Excel文件


2. 导出Json文件,选择属性模式


3. 使用文本编辑器查看Json数据

4. 在程序中添加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());}

5. 获取Json文件中的数据

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,%d",name,level,hp,attack);}

6. 程序运行结果