读书人

JsonCpp解析\u中文乱码有关问题

发布时间: 2013-11-02 19:41:10 作者: rapoo

JsonCpp解析\u中文乱码问题。
大家好。Jsoncpp 0.5 解析出来的中文还是乱码。

网上两个方法如下:


方法一:http://www.cocoachina.com/downloads/code/2012/0419/4172.html

方法二:http://blog.csdn.net/harrycris/article/details/7733386


但是都不行。那位前辈能帮忙解决下。对编码方面东西实在不了解。


关键似乎在这个函数上:

static std::string codePointToUTF8(unsigned int cp)
{
std::string result;

// based on description from http://en.wikipedia.org/wiki/UTF-8

if (cp <= 0x7f)
{
result.resize(1);
result[0] = static_cast<char>(cp);
}
else if (cp <= 0x7FF)
{
result.resize(2);
result[1] = static_cast<char>(0x80 | (0x3f & cp));
result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
}
else if (cp <= 0xFFFF)
{
result.resize(3);
result[2] = static_cast<char>(0x80 | (0x3f & cp));
result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
}
else if (cp <= 0x10FFFF)
{
result.resize(4);
result[3] = static_cast<char>(0x80 | (0x3f & cp));
result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
}

return result;


那位帮忙下呀 谢谢啦
[解决办法]
我也正在折腾这个问题
[解决办法]
明明是转的UTF8, 咋又成乱码了.

读书人网 >C++

热点推荐