最先的時候jsoncpp不是這樣的。json
Json::Value root; root["name"] = "你的名字"; //Chinese, and use utf8 Json::FastWriter fwriter; std::string retStr = fwriter.write(root); std::cout << retStr;
以前的jsoncpp返回是這樣的ui
spa
{"name", "你的名字"}
如今成這樣了調試
{"name", "\u4f60\u7684\u540d\u5b57"}
不過通過個人單步調試發現,jsoncpp還有個配置的。就是能夠設置就是emitUTF8這個配置。code
std::string JsonToString(const Json::Value & root) { static Json::Value def = []() { Json::Value def; Json::StreamWriterBuilder::setDefaults(&def); def["emitUTF8"] = true; return def; }(); std::ostringstream stream; Json::StreamWriterBuilder stream_builder; stream_builder.settings_ = def;//Config emitUTF8 std::unique_ptr<Json::StreamWriter> writer(stream_builder.newStreamWriter()); writer->write(root, &stream); return stream.str(); }