How to work with UTF-16¶
Example on how to work with UTF-16 strings
We have this json, which includes UTF-16 characters:¶
{
"game_title": "H\u03bblf Life 3",
"description": "\"There's no such thing as H\u03bblf-Life 3\" By this point in the story you won't be too surprised to read the words ...",
"price": 4999,
"id": 23032020
}
Getting the u16strings (C++):¶
Json json;
json.Parse(aboveJsonCode);
std::string rawTitle = json["game_title"];
std::string rawDescr = json["description"];
std::u16string gameTitle = UTF16Compatibility::ParseUTF16(rawTitle);
std::u16string gameDescr = UTF16Compatibility::ParseUTF16(rawDescr);
Putting the u16strings back in (C++):¶
json["game_title"] = UTF16Compatibility::EscapeUTF16(gameTitle);
json["description"] = UTF16Compatibility::EscapeUTF16(gameDescr);
That's it.