How to Create a JSON string using a Cocos2d-x

Source: Internet
Author: User

How to Create a JSON string using a Cocos2d-x

 

This section describes how to compile a JSON string. Directly accessing the code is relatively simple.

MakeJson. h

 

//// MakeJson. h // cpp4 // Created by du jia on 14-9-9. /// # ifndef _ cpp4 _ MakeJson __# define _ cpp4 _ MakeJson __# include cocos2d. h # include json/document. h # include json/writer. h # include json/stringbuffer. hUSING_NS_CC; class MakeJson: public Ref {public: CREATE_FUNC (MakeJson); virtual bool init (); std: string getTestJson ();}; # endif/* defined (_ cpp4 _ MakeJson __)*/

 

 

MakeJson. cpp

 

//// MakeJson. cpp // cpp4 // Created by du jia on 14-9-9. //// # include MakeJson. hbool MakeJson: init () {bool bRef = false; do {bRef = true;} while (0); return bRef;} std: string MakeJson: getTestJson () {auto path = FileUtils: getInstance ()-> getWritablePath (); log (% s, path. c_str (); // Add a json file path under this path. append (test. json); rapidjson: Document d1; d1.SetObject (); rapidjson: Document: AllocatorType & allocator = d1.GetAllocator (); rapidjson: Value array (rapidjson: kArrayType ); rapidjson: Value object (rapidjson: kObjectType); object. addMember (id, 1, allocator); object. addMember (name, 234, allocator); object. addMember (ages, 111, allocator); array. pushBack (object, allocator); d1.AddMember (propety, PLAYER-TO, allocator); d1.AddMember (player, array, allocator); rapidjson: StringBuffer; rapidjson: Writer
 
  
Write (buffer); d1.Accept (write); return StringUtils: format (% s, buffer. GetString ());}
 



 

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.