cocos2d-x3.1 Generating JSON strings

Source: Internet
Author: User

#include "HelloWorldScene.h" #include "json/document.h" #include "json/writer.h" #include "json/stringbuffer.h" # Include <iostream>using namespace Rapidjson; USING_NS_CC;        scene* Helloworld::createscene () {//' scene ' is an Autorelease object auto scene = Scene::create ();    ' Layer ' is an Autorelease object auto layer = Helloworld::create ();    Add layer as a child to scene scene->addchild (layer); Return the scene return scene;}    On "Init" you need to initialize your Instancebool helloworld::init () {bool BRet = false; do{cc_break_if (!        Layer::init ());        Auto Path = Fileutils::getinstance ()->getwritablepath ();        Log ("Path =%s", path.c_str ());                Path.append ("Test.json");        Rapidjson::D ocument Document; Document.        SetObject (); Rapidjson::D ocument::allocatortype& allocator = Document.        Getallocator ();        Rapidjson::value Array (rapidjson::karraytype); Rapidjson::value Array1 (Rapidjson::karraYType);        Rapidjson::value object (Rapidjson::kobjecttype);        Rapidjson::value Object1 (Rapidjson::kobjecttype); Object.        AddMember ("Transtype", "Callcenter", allocator); Object.        AddMember ("Transcode", 00011002, allocator); Object.        AddMember ("Subtranscode", 2, allocator); Object.        AddMember ("TransDate", 2013-6-17, allocator); Object.        AddMember ("Transtime", "15:23:25", allocator); Object.        AddMember ("Transseq", 00011002-2201361700017, allocator); Object.        AddMember ("Operator", "Web", allocator); Object.        AddMember ("Rownumstart", 1, allocator); Object.        AddMember ("Pagerownum", allocator); Object.        AddMember ("Pageflag", 0, allocator); Object.        AddMember ("Totalrownum", "", allocator); Object.        AddMember ("ResultCode", "", allocator); Object.        AddMember ("Resultmsg", "", allocator); Object.        AddMember ("Orderflag", 0, allocator); Object.        AddMember ("OrderField", "", allocator); Array. Pushback (object, allocator); Object1.        AddMember ("Contno", 662206117012, allocator); Array1.                Pushback (Object1, allocator); Document.        AddMember ("Baseinfo", array, allocator); Document.                        AddMember ("Inputdata", array1, allocator);        StringBuffer buffer;        Rapidjson::writer<stringbuffer> Writer (buffer); Document.        Accept (writer); Log ("%s", buffer.                GetString ());        file* fp = Std::fopen (Path.c_str (), "at+");        Ccassert (fp! = NULL, "File open error"); Auto str = Stringutils::format ("%s", buffer.        GetString ());        Auto length = Str.length ();        Log ("length =%lu", Str.length ());        Fwrite (Str.c_str (), length, 1, FP);                Fclose (FP);    BRet = true;    }while (0); return bRet;}

cocos2d-x3.1 Generating JSON strings

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.