1. 程式人生 > >C++ \u中文亂碼解決辦法

C++ \u中文亂碼解決辦法

以下是一個jsoncpp解析有\u中文json檔案的例子:std::string showname = rootOne[“showname”].asString();int len=strlen(showname.c_str())+1;char outch[MAX_PATH];WCHAR * wChar=new WCHAR[len];wChar[0]=0;MultiByteToWideChar(CP_UTF8, 0, showname.c_str(), len, wChar, len);WideCharToMultiByte(CP_ACP, 0, wChar, len, outch , len, 0, 0);delete [] wChar;char* pchar = (char*)outch;這樣就得到一個char * 可用於其他的轉換如果要把pchar顯示到控制元件上(比如ListView):int len=strlen(pchar)+1;WCHAR outName[MAX_PATH];MultiByteToWideChar(CP_ACP, 0, pchar, len, outName, len);ListView_SetItemText(hWndListView, index, 2, outName);HJAA.NET原創,轉載請附帶本文連結:http://www.hjaa.net/articles/2012/09/1083.html