My problem is that when I get -for example- the word "سلام" from a JSON file, the output will be "????", but if I get -for example- "Peace" from the same JSON file, the output will be "Peace".
This the game that I am using (I get it from this Unity tutorial):
private void LoadGameData()
{
// Path.Combine combines strings into a file path
// Application.StreamingAssets points to Assets/StreamingAssets in the Editor, and the StreamingAssets folder in a build
string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName);
if (File.Exists(filePath))
{
// Read the json from the file into a string
string dataAsJson = File.ReadAllText(filePath);
// Pass the json to JsonUtility, and tell it to create a GameData object from it
GameData loadedData = JsonUtility.FromJson<GameData>(dataAsJson);
// Retrieve the allRoundData property of loadedData
allRoundData = loadedData.al_asallRoundDataela;
}
else
{
Debug.LogError("Cannot load game data!");
}
}
Can anyone help me?
This is likely due to a mismatch in the Encoding. Use the ReadAllText overload which allows you to specify the proper Encoding to use when reading the file.
The default overload will assume UTF-8 unless it can detect UTF-32. Any other encoding will come through incorrectly.
I think the right code is:
var arabic = Encoding.GetEncoding(1256);
File.ReadAllText(filePath,arabic);