Skip to content

Instantly share code, notes, and snippets.

@uxdxdev
Created December 21, 2016 15:11
Show Gist options
  • Save uxdxdev/d7652dcd852081f9dd709022b6d83a22 to your computer and use it in GitHub Desktop.
Save uxdxdev/d7652dcd852081f9dd709022b6d83a22 to your computer and use it in GitHub Desktop.
RapdiJson writing json data to file example C++
#include <fstream>
#include "external/json/stringbuffer.h"
#include "external/json/writer.h"
void JsonParser::JsonToFile(rapidjson::Document &jsonObject, std::string &fullpath) {
std::ofstream outputFile;
outputFile.open(fullpath);
if(outputFile.is_open()) {
std::string jsonObjectData = JsonToString(jsonObject);
outputFile << jsonObjectData;
}
outputFile.close();
}
std::string JsonParser::JsonToString(rapidjson::Document &jsonObject) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> jsonWriter(buffer);
jsonObject.Accept(jsonWriter);
return buffer.GetString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment