lundi 22 juillet 2019

Save json with rapidjson directly on file

I'm java programmer and I'm learning C++ for my personal project for a parser bitcoin core, my parser converts the information on file dat bitcoin to the json file.

Now my problem is when I create the big json with rapidjson with Writer on StringBuffer

This is a simple example my DAO

void DAOJson::serializationWithRapidJson(Person &person) {
    rapidjson::StringBuffer s;
    rapidjson::Writer<rapidjson::StringBuffer> writer(s);
    person.toRapidJson(writer);
    unique_ptr<string> json(new string(s.GetString()));
    cout << *json;
    ofstream stream(DIR_HOME + "dump_rapidJson_test.json");
    stream << *json;
    json.reset();
    stream.close();
}

My question is

Is possible with rapidjson create the json on the file and not on the string? because I must save my memory

the example of the code that I would like to

rapidjson::Writer<rapidjson::FileWriter> writer(s);

Aucun commentaire:

Enregistrer un commentaire