COCOS2DX HTTP Network Programming (ii)--json data parsing __ Applet

Source: Internet
Author: User

The previous article explains how to use the initiate request and accept data, and this article begins using Libjson to parse network JSON data .

COCOS2DX itself does not have a JSON parsing class library, we introduce libjson here to parse. Download Address:

The version I am currently using is 7.6.1. 1. Download Libjson and unzip the download, extract out, here to our useful documents are: libjson.h; JSONOptions.h; All files under the _internal->source folder; All files under the _internal->dependencies folder. Copy these files and folders and place them in the classes directory in your project, noting that the file hierarchy cannot be changed . 2. Add source to project for clearer project structure, create a new folder for JSON source.
Then add the head culture and CPP files in the Libjson. The following figure is the file I added; 3. For JSON parsing , first introduce Libjson into your code:

	#include "Libjson.h"
Then you can write the JSON parsing class. If not, you can refer to the documents in the->getting started->c++ interface under the downloaded Libjson folder.
Jsonnode N (json_node);
	N.push_back (Jsonnode ("Roota", "Value in parent Node"));
	Jsonnode c (json_node);
	C.set_name ("Childnode");
	C.push_back (Jsonnode ("Childa", "String Value"));
	C.push_back (Jsonnode ("Childb");
	N.push_back (c);
	std::string JC = n.write_formatted ();
	Std::cout << JC << Std::endl;
OK, and then run and view the output.

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: 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.