JSon response is UTF-8 and it must be converted to wchar_t right away

This commit is contained in:
King_DuckZ 2013-08-21 15:21:16 +02:00
parent 21476e0a5d
commit 402f90b5df
3 changed files with 8 additions and 1 deletions

View file

@ -105,6 +105,12 @@ std::string HttpReader::GetPage (const std::string& parAddress) const {
return localString; return localString;
} }
///-----------------------------------------------------------------------------
///-----------------------------------------------------------------------------
std::wstring HttpReader::GetPageW (const std::string& parAddress) const {
return cconv::MultibyteToWide(this->GetPage(parAddress));
}
///----------------------------------------------------------------------------- ///-----------------------------------------------------------------------------
///----------------------------------------------------------------------------- ///-----------------------------------------------------------------------------
std::string HttpReader::UrlEncode (const wchar_t* parWord) { std::string HttpReader::UrlEncode (const wchar_t* parWord) {

View file

@ -7,6 +7,7 @@ public:
~HttpReader ( void ) noexcept; ~HttpReader ( void ) noexcept;
std::string GetPage ( const std::string& parAddress ) const; std::string GetPage ( const std::string& parAddress ) const;
std::wstring GetPageW ( const std::string& parAddress ) const;
std::string UrlEncode ( const wchar_t* parWord ) __attribute__((pure)); std::string UrlEncode ( const wchar_t* parWord ) __attribute__((pure));
std::string UrlEncode ( const std::wstring& parWord ) __attribute__((pure)); std::string UrlEncode ( const std::wstring& parWord ) __attribute__((pure));

View file

@ -50,7 +50,7 @@ namespace {
oss << "http://api.wordreference.com/" << ApiVersion << "/" oss << "http://api.wordreference.com/" << ApiVersion << "/"
<< parKey << "/json/" << parFrom << parTo << "/" << parHttp.UrlEncode(parWord); << parKey << "/json/" << parFrom << parTo << "/" << parHttp.UrlEncode(parWord);
std::string jsonResponse(parHttp.GetPage(oss.str())); std::wstring jsonResponse(parHttp.GetPageW(oss.str()));
return libjson::parse(libjson::to_json_string(jsonResponse)); return libjson::parse(libjson::to_json_string(jsonResponse));
} }