Cocos2d-x3.0 Json解析
2020-11-25 04:55
标签:cocos2d-x rapidjson document json 解析 2dx3.0下JSON解析库官方已经集成好了,我们引用就OK。 JSON文件hello.json内容
.h头文件
Cocos2d-x3.0 Json解析,搜素材,soscw.com Cocos2d-x3.0 Json解析 标签:cocos2d-x rapidjson document json 解析 原文地址:http://blog.csdn.net/qqmcy/article/details/24920145{"pets":["dog","cat"],"stuInfo":{"stuAge":"23","stuName":"zhangsan","birthday":"1990-01-12"},"username":"tomsfff","other":[true,30]}
#include "cocos-ext.h"
#include "tinyxml2/tinyxml2.h"
.cpp
//获取文件路径
const char* file_path = FileUtils::getInstance()->fullPathForFilename("hello.json").c_str();
log("external file path = %s",file_path);
rapidjson::Document d1;
std::string contentStr = FileUtils::getInstance()->getStringFromFile(file_path);
d1.Parse(contentStr.c_str());
//打印JSon文件的内容
printf("%s\n",contentStr.c_str());
//获取JSon中数组的方法
const rapidjson::Value& v = d1["pets"];
if (v.IsArray()) {
//这里一定要注意 变量i 一定要是 unsigned int 不然会报错
for (unsigned int i = 0; i