How to get JsonCPP values as strings?

て烟熏妆下的殇ゞ 提交于 2019-12-01 19:35:19

You can trivially create your own writer that does whatever you want. Have look at the code for StyledWriter. The CRLF's you don't like come from StyledWriter::Write. You can create your own writer class that doesn't have those CRLF's.

If you don't mind modifying the library, change the writer so that functions like writeValue are protected rather than private. Then you can derive your own class from StyledWriter with a different Write function and still use the various write* functions to do the details of the conversion.

The project has moved to GitHub.

To avoid all linefeeds, use a StreamWriterBuilder:

Json::Value whatever = ...;
Json::StreamWriterBuilder builder;
builder.settings_["indentation"] = "";
std::string out = Json::writeString(builder, whatever);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!