Wininet HTTP请求返回UTF8的JSON数组乱码

wininet 封装 http请求(POST/GET)WEB服务器返回一个UTF8的JSON数组,不经过编码则会显示为乱码,但,通过转换后,中文虽然正确显示,但会有多余的“?”号出现。
过程如下:
int main(int argc, char *argv[]){

AKHTTPWrapper akwrapper;
std::string responseString;
    if(akwrapper.Connect("http://www.chinaeko.net")){
        if(akwrapper.Request("/api.php?m=Business&a=doc2")){
            char buf[1024]="\0";
            while(akwrapper.Response(reinterpret_cast<unsigned char *>(buf), 1024))
                responseString +=(char*) buf ;
        }
        akwrapper.Close();
            std::wstring finalString = UTF8toUnicode(&responseString);
            cout << finalString << endl;
    }
    return 0;
}

//UTF8 to Unicode
std::wstring AKHTTPWrapper::UTF8toUnicode(const std::string &str){
    int  len = 0;
    len = str.length();
    int  unicodeLen = ::MultiByteToWideChar( CP_UTF8,0,str.c_str(),-1,NULL,0);
    wchar_t *  pUnicode;
    pUnicode = new  wchar_t[unicodeLen+1];
    memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
    ::MultiByteToWideChar( CP_UTF8,0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen);  
     wstring  rt;
     rt = (wchar_t*)pUnicode;

     delete  pUnicode;
     return  rt;  
}
查看全部
Jasonsystem
程序猿KL
2015/01/12 13:41
  • post
  • get
  • 乱码
  • http
  • net
  • 点赞
  • 收藏
  • 回答
    私信

4个回复