Getting non-literal string from JSON in c++ UE4

I am using the FJsonObject class to get JSON from a file I am reading. These files contain the localization for my game.

Everything seemed to go smoothly, until I realized that the getStringWithKey method that I was using was returning ANSI FStrings only. I need these to return UTF-8 FStrings so that the Chinese, Japanese, etc. languages work.

FString AJSONContainer::getStringWithKey(FString key)
{
	return storedJSON->GetStringField(key);
}

Thus far, I’ve managed to get the value as an FJsonValueObject, but I have been unable to figure out how to get the value as a std::string or a TCHAR so that I can convert it to a wide-character string.

FString AJSONContainer::getUnicodeStringWithKey(FString key)
{
	FJsonValueObject out = storedJSON->GetObjectField(key);

}

The only method I see on FJsonValueObject that is relevant is .AsString(), but that returns as an FString, and I can’t run FString through the TEXT() method.

Any ideas on how I can convert this FString to UTF-8?

Hi,

You can use the FTCHARToUTF8 object to convert an FString:

FTCHARToUTF8 ConvertedStr(*MyFString);
const UTF8CHAR* ConvertedPtr = ConvertedStr.Get();

ConvertedPtr is legal as long as ConvertedStr exists.

Steve