我的问题是,当我从JSON文件中获取-for example-单词"سلام“时,输出将是”?“,但如果我从同一JSON文件中获取-for example-”سلام“,则输出将是”和平“。
这就是我正在使用的游戏(我是从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!");
}
}
有谁可以帮我?
发布于 2018-06-04 07:09:54
这可能是由于编码中的不匹配造成的。使用ReadAllText重载,它允许您在读取文件时指定要使用的正确编码。
默认重载将采用UTF-8,除非它可以检测到UTF-32。任何其他编码都将无法正确通过。
我认为正确的代码是:
var arabic = Encoding.GetEncoding(1256);
File.ReadAllText(filePath,arabic);
https://stackoverflow.com/questions/50671764
复制相似问题