Created
December 21, 2016 15:11
-
-
Save uxdxdev/d7652dcd852081f9dd709022b6d83a22 to your computer and use it in GitHub Desktop.
RapdiJson writing json data to file example C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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