JSON 文件中的统一阿拉伯语文本

Unity Arabic Text From JSON File

我的问题是,当我从 JSON 文件中获取 - 例如 - 单词“سلام”时,输出将是“????”,但如果我 - 例如 - "Peace" 来自同一个 JSON 文件,输出将是 "Peace".

这是我正在使用的游戏(我从 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!");
    }
}

谁能帮帮我?

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

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

我认为正确的代码是:

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