Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cocos2d-x JSON文件解析_C++_Json_Parsing_Cocos2d X - Fatal编程技术网

C++ cocos2d-x JSON文件解析

C++ cocos2d-x JSON文件解析,c++,json,parsing,cocos2d-x,C++,Json,Parsing,Cocos2d X,我有一个.json文件,其中包含一个字典数组。你能告诉我解析它的好方法吗?我使用的是cocos2d-x3.0-alpha版本和json类,它们位于external/json目录中 我试过: Array* items = Array::createWithContentsOfFile("test.json"); 及 但是它们都不起作用——第一个方法返回一个空数组,第二个方法生成一个_根变量,包含整个json,但我不能将其放入数组中,并为数组的每个元素创建一个单独的dictionary对象(这正是

我有一个.json文件,其中包含一个字典数组。你能告诉我解析它的好方法吗?我使用的是cocos2d-x3.0-alpha版本和json类,它们位于external/json目录中

我试过:

Array* items = Array::createWithContentsOfFile("test.json");


但是它们都不起作用——第一个方法返回一个空数组,第二个方法生成一个_根变量,包含整个json,但我不能将其放入数组中,并为数组的每个元素创建一个单独的dictionary对象(这正是我试图做的)。

使用上面提到的JsonCPP,但使用CCFileUtils类

unsigned long filesize = 0;
std::string content;
std::string fullPath = "path relative to your androidmanifest.xml/index.json"

unsigned char* fileData = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &filesize);
content.append((char*)fileData);
delete[] fileData;

Json::Value jsonresult;
Json::Reader reader;
bool parsingSuccessful = reader.parse( content, jsonresult );
if ( !parsingSuccessful )
{
// report to the user the failure
return false;
}

你可以用rapidjson
unsigned long filesize = 0;
std::string content;
std::string fullPath = "path relative to your androidmanifest.xml/index.json"

unsigned char* fileData = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &filesize);
content.append((char*)fileData);
delete[] fileData;

Json::Value jsonresult;
Json::Reader reader;
bool parsingSuccessful = reader.parse( content, jsonresult );
if ( !parsingSuccessful )
{
// report to the user the failure
return false;
}