Cocos2d-x Read JSON file
Under the Resource folder, add the Data.json file
New-"other-" empty-"open"
Just create a new JSON file,
Data.json content is as follows
[{' name ': ' Hello ', ' age ': 22},{' name ': ' World ', ' age ': 23}]
To read an XML file, first introduce the header file: #include <json/document.h>
Add the following code to the bool Helloworld::init ()
1 //using the tools built into the COCOS2DX2 Rapidjson::D ocument D;3 //parsing File parse< parsing method (0: representing default parsing) > (data to Parse (Get Data.json by Tool Class))4d.parse<0> (Fileutils::getinstance ()->getstringfromfile ("Data.json"). C_STR ());5 //gets the first element in the file, d[the index value, 0 is empty, forcing the type to convert [properties in the file]6Log"%s", d[(int)0]["name"]. GetString ());7Log"%s", d[(int)1]["name"]. GetString ());
Cocos2d-x Read JSON file