Json3
来源:互联网 发布:淘宝自定义代码 编辑:程序博客网 时间:2024/06/03 14:15
voidInputLayer::readJson()
{
rapidjson::Document _doc;
bool bRet =false;
ssize_t size =0;
unsignedchar *pBytes = NULL;
do {
pBytes =FileUtils::getInstance()->getFileData("protocal.json","r", &size);
CC_BREAK_IF(pBytes ==NULL || strcmp((char*)pBytes,"") == 0);
std::string load_str((constchar*)pBytes, size);
CC_SAFE_DELETE_ARRAY(pBytes);
_doc.Parse<0>(load_str.c_str());
CC_BREAK_IF(_doc.HasParseError());
//生成json文档对像
if(!_doc.IsObject())
return;
//是否有此成员
if(!_doc.HasMember("entities"))
return;
//通过[]取成员值,再根据需要转为array,int,double,string
constrapidjson::Value &pArray = _doc["entities"];
//是否是数组
if(!pArray.IsArray())
return;
for (rapidjson::SizeType i =0; i < pArray.Size(); i++)
{
constrapidjson::Value &p = pArray[i];
if(p.HasMember("entity"))
{
constrapidjson::Value &valueEnt = p["entity"];
if(valueEnt.HasMember("TapOpposite") && valueEnt.HasMember("Interval") && valueEnt.HasMember("BallNum"))
{
constrapidjson::Value &tapOpposite = valueEnt["TapOpposite"];
int tapOp = tapOpposite.GetInt(); //得到int值
constrapidjson::Value &interval = valueEnt["Interval"];
float inter = interval.GetDouble(); //得到float,double值
constrapidjson::Value &ballNum = valueEnt["BallNum"];
int ball = ballNum.GetInt(); //得到int值
CCLOG("tapOp==%d, inter==%f, ball==%d", tapOp, inter, ball);
}
}
else
{
return;
}
}
bRet =true;
}while (0);
}
"entities": [
{
"entity": {
"TapOpposite": 0,
"Interval": 0.95,
"BallNum": 1
}
},
{
"entity": {
"TapOpposite": 0,
"Interval": 0.91,
"BallNum": 2
}
},
{
"entity": {
"TapOpposite": 0,
"Interval": 0.95,
"BallNum": 3
}
}
]
}
- JSON3
- Json3
- Android中Gson解析详解json3
- JSON3:JSON与XML数据之间的转换
- JavaScript中解析JSON --- json.js 、 json2.js 以及 json3.js的使用区别
- HDU 4961(杭电多校#9 1002题)Boring Sum(瞎搞)
- c++ 学习笔记(高级linux编程) day7
- Spring - 使用ApplicationContextAware得到一个ApplicationContext对象
- 如何在Android应用中使用百度地图api
- 用指针玩字符串--连接
- Json3
- html5的研究心得
- Gallery代码分析及纵向Gallery实现方法
- DbgPrint/KdPrint输出格式控制
- c++ 学习笔记(高级linux编程) day8
- WebView中支持input的file的选择
- 2014多校1009--hdu4968--Improving the GPA(平均成绩的最大最小平均学分)
- hdu 4960 Another OCD Patient
- c++ 学习笔记(高级linux编程) day9