首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >来自JSON文件的Unity阿拉伯语文本

来自JSON文件的Unity阿拉伯语文本
EN

Stack Overflow用户
提问于 2018-06-04 07:06:10
回答 1查看 812关注 0票数 1

我的问题是,当我从JSON文件中获取-for example-单词"سلام“时,输出将是”?“,但如果我从同一JSON文件中获取-for example-”سلام“,则输出将是”和平“。

这就是我正在使用的游戏(我是从this Unity tutorial得到的):

代码语言:javascript
复制
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!");
    }
}

有谁可以帮我?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 07:09:54

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

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

我认为正确的代码是:

代码语言:javascript
复制
var arabic = Encoding.GetEncoding(1256);
 File.ReadAllText(filePath,arabic);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50671764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档