cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Non-ASCII characters not converted properly in http_response.extract_utf8_string in MSVC 2019

Open jdx-john opened this issue 2 years ago • 0 comments

My server is returning the following as shown in PostMan:

image

{
  "status": "FEL: Det valda objektet för händelsen"
}

In C++ VS2019, reading as a wstring is perfect but if I call response.extract_utf8_string() the JSON has messed up characters, in exactly the same way if I use utility::conversions:

	std::string status = "unknown";
	if (json.has_string_field(L"status"))
	{
		auto tmp = json[L"status"].as_string();
		status = utility::conversions::to_utf8string(tmp);
	}

tmp: L"FEL: Det valda objektet för händelsen" status: "FEL: Det valda objektet för händelsen"

I need to use this value in a std::exception which only takes std::string what is the correct way to convert and why isn't utf8 working in the first place, when that's how the content is being encoded in the response?

jdx-john avatar May 16 '23 11:05 jdx-john