Cocos2d-x Read JSON file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.