加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos Studio 数据编辑器新手使用教程

发布时间:2020-12-14 16:31:30 所属栏目:百科 来源:网络整理
导读:1. 在数据编辑器中导入Excel文件 650) this.width=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" style="border:0px;text-align:center;margin:10px 0px;" src="http://img.my.csdn.net/uploads/201405/26/1401069170_4308.png"> 650) th

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


spacer.gif

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


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

spacer.gif

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

6. 程序运行结果

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读