cocos2d-x3.0 JSON parsing

Source: Internet
Author: User

2DX3.0 Next JSON parsing library officer and integration. Let's take a look at it OK.

JSON file Hello.json content

{"Pets": ["Dog", "cat"], "Stuinfo": {"stuage": "All", "Stuname": "Zhangsan", "Birthday": "1990-01-12"}, "username": " Tomsfff "," other ": [true,30]}

. h header File

#include "cocos-ext.h" #include "json/document.h"

. cpp

Gets the file path        const char* File_path = Fileutils::getinstance ()->fullpathforfilename ("Hello.json"). C_str ();       Log ("External file path =%s", file_path);                Rapidjson::D ocument d1;        std::string contentstr = fileutils::getinstance ()->getstringfromfile (file_path);        D1. Parse<0> (Contentstr.c_str ());        Print the contents of the JSON file        printf ("%s\n", Contentstr.c_str ());                Gets the method of the array in JSON        const rapidjson::value& v = d1["pets"];        if (V.isarray ()) {            //must note here that the  variable I must   be unsigned int  otherwise it will error for            (unsigned int i = 0; i< v.size () ; ++i) {                                 const rapidjson::value &val = V[i];                Log ("%s", Val. GetString ());            }                    } else        {            const rapidjson::value& val = v["Stuage"];            Log ("Val. GetString () =%s ", Val. GetString ());                    }

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

cocos2d-x3.0 JSON parsing

Related Article

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.