您的位置:首页 > 移动开发 > Cocos引擎

[cocos2dx]学习笔记 jsonDict

2014-08-01 16:26 204 查看
jsondict是一种现在移动互联网用得比较多的一种定义数据的结构,下面来介绍一下

cpp

this->index = index;
this->type =
jsonDict["shop"][index]["type"].GetString();
this->gold =
jsonDict["shop"][index]["gold"].GetInt();
this->img =
jsonDict["shop"][index]["img"].GetString();
this->id =
jsonDict["shop"][index]["id"].GetInt();
this->desc =
jsonDict["shop"][index]["desc"].GetString();
data.json

"shop":
[
{

"type":"item",
"id":0,

"gold":300,

"img":"zhuangb025.png",

"desc":"猎枪:伤害高,后坐力小,高仿猎枪,不伤手无残留,颇受男同胞们的喜欢。"
},
{

"type":"item",
"id":1,

"gold":800,

"img":"zhuangb079.png",

"desc":"捕猎网:覆盖面积更广,比它网好用多了,喜欢养小猫小狗的人不妨买回去试一下"
},
{

"type":"item",
"id":2,

"gold":6000,

"img":"zhuangb080.png",

"desc":"弹射陷阱:全国销量领先的捕猎器件,弹弹弹,弹走小怪兽"
},

this->type = jsonDict["shop"][index]["type"].GetString();
的意思是给type赋值,值为shop类的index(索引)若index为0,则为第一个大括号的内容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: