比如返回的 json 如下
{
"word":"\u4f60\u597d"
}
这里的 word 是单斜杆的。
我在 C++中重写了这个 http 服务的接口,但是我只能通过以下的代码将中文转成 unicode 码
static std::string ConvertWStringToUnicodeEscape(const std::wstring& unicode_str)
{
std::wstring unicode_str_copy = unicode_str;
std::stringstream ss;
for (std::wstring::iterator iter = unicode_str_copy.begin(); iter != unicode_str_copy.end(); ++iter)
{
if (*iter <= 127)
ss << (char)*iter;
else
ss << "\\u" << std::hex << std::setfill('0') << std::setw(4) << (int)*iter;
}
return ss.str();
}
在 C++中输出单斜杠就必须加转义符号,这造成了返回的 json 成了双斜杆
{
"word":"\\u4f60\\u597d"
}
各位大佬有什么好的解决方法吗?