来自 JSON 文件的统一阿拉伯语文本



我的问题是,当我从 JSON 文件中获得单词"سلام"时,输出将是"????",但如果我从同一个 JSON 文件中得到 - 例如 - "和平",输出将是"和平"。

这是我正在使用的游戏(我从这个 Unity 教程中得到它(:

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!");
}
}

谁能帮我?

这可能是由于编码不匹配。使用ReadAllText重载,它允许您指定在读取文件时使用的正确编码。

默认重载将采用 UTF-8,除非它可以检测到UTF-32。任何其他编码都将错误地通过。

我认为正确的代码是:

var arabic = Encoding.GetEncoding(1256);
File.ReadAllText(filePath,arabic);

最新更新