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