#include"rapidjson/document.h"// rapidjson's DOM-style API#include"rapidjson/prettywriter.h"// for stringify JSON
rapidjson::Document readJson(constchar* jsonFile){
std::ifstream t;longlong length =0;
t.open(jsonFile);// open input fileif(!t.is_open()){LOGGING_ERROR("Config file open error, file path : %s", jsonFile);}
t.seekg(0, std::ios::end);// go to the end
length = t.tellg();// report location (this is the length)
t.seekg(0, std::ios::beg);// go back to the beginningchar* configData = new char[length];// allocate memory for a buffer of appropriate dimensionif(!configData){LOGGING_ERROR("Config file new memory error");}
t.read(configData, length);// read the whole file into the buffer
t.close();// close file handle
rapidjson::Document configDocument;
configDocument.Parse<rapidjson::kParseStopWhenDoneFlag>((constchar*)configData);if(!configDocument.IsObject()){LOGGING_ERROR("%s content is not json type", jsonFile);}free(configData);return configDocument;}