Question

I am trying to use rapidjson to output itself to a string to save to a database, using the following code :

StringBuffer buffer;
Writer<FileStream> writer(buffer);
rest.Accept(writer);
string reststring = buffer.GetString();

where rest is a rapidjson::Document.

However I get the following error :

no matching function for call to ‘rapidjson::Writer<rapidjson::FileStream>::Writer (rapidjson::StringBuffer&)’.

which is strange because the author of rapidjson recommended this method in an answer to a previous SO question.

Was it helpful?

Solution

I must have been tired at 9 last night when I wrote this piece of code.

Changing

Writer<FileStream> writer(buffer);

to

Writer<StringBuffer> writer(buffer);

solves the problem.

OTHER TIPS

Try to use rapidjson::StringBuffer and rapidjson::Writer for get string output.

rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
rest.Accept(writer);
std::string str = buffer.GetString();

Here you can get value in both string as well as std::string. Above I used std::string for get value. This works...

As your compiler suggest, you have to modify your code in:

 StringBuffer buffer;
 Writer<FileStream> writer(&buffer);

Or:

 StringBuffer* buffer;
 Writer<FileStream> writer(buffer);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top