I get a JSON string from the server, it's type is std::wstring
and its content is:
[{
"nodeRef": "workspace://SpacesStore/12f1623f-196a-4289-a9af-07f3d1ee7c4e",
"name": "/Oracle® Fusion Developer's Guide for Oracle Application Development Framework b31974.txt",
"type": "cm:content",
"sys:node-dbid": "228,137",
"cm:modified": "2013-09-23 13:51:33.682 +0800",
"size": "260",
"checksum": "4D59ABBC6A45BE32750CAF541EED29C4"
}]
I try to convert it to std::string
in order to use rapidjson to deal with the string, but failed when coverting "®", since the "®" changes to "?". I try these methods bellow but none of them is successful:
//method 1
return (char *)(_bstr_t)wstr.c_str();
//method 2
const wchar_t* wp = wstr.c_str();
int len= WideCharToMultiByte(CP_ACP,0,wp,-1,NULL,0,NULL,NULL);
char * m_char=new char[len];
WideCharToMultiByte(CP_ACP,0,wp,-1,m_char,len,NULL,NULL);
m_char[len-1]='\0';
std::string strTemp(m_char);
delete [] m_char;
return strTemp;
//method 3
std::string curLocale = setlocale(LC_ALL, NULL);
setlocale(LC_ALL, "en-us");
const wchar_t* _Source = wstr.c_str();
size_t _Dsize = 2 * wstr.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest,0,_Dsize);
wcstombs(_Dest,_Source,_Dsize);
std::string result = _Dest;
delete []_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
I don't know why! anybody can help? thanks!
my locale is first "Chinese (Simplified)_People's Republic of China.936", when I change it to "en-us" & use method 2, the result is OK. the "®" remains the same. But most of the computers here are "chs" by default. So is there another solution without change the system language?