A
A
Anton Vertov2017-07-05 07:56:37
JSON
Anton Vertov, 2017-07-05 07:56:37

JSON file encoding in Unity 3D. What to put for Cyrillic?

Good day. I am making multilanguage for my game on JSON. The English dictionary is loaded without problems, but when I put Russian - the variables are just empty, nothing is displayed. I put the ANSI file encoding - squares (unknown characters) are issued. What encoding should be used for normal display? Everything is fine on the computer - the problem is on the ANDROiD device . The code is as follows (the compiler does not throw any errors):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class LangSystem : MonoBehaviour {

    private string json;
    public static lang lng = new lang();

    void Awake()
    {
        LangLoad();
    }

    void LangLoad()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        string path = Path.Combine(Application.streamingAssetsPath, "Language/ru_RU.json");
        WWW reader = new WWW(path);
        while (!reader.isDone) { }
        json = reader.text;
        lng = JsonUtility.FromJson<lang>(json);
#endif
#if UNITY_EDITOR
        json = File.ReadAllText(Application.streamingAssetsPath + "/Language/ru_RU.json");
        lng = JsonUtility.FromJson<lang>(json);
#endif

    }
}

public class lang
{
    public string[] sports = new string[100];
    public string[] geo = new string[100];

    public string applicationName;
    public string startGame;
    public string rules;
    public string settings;
    public string quit;
}

JSON file format:
{
  "applicationName":"МОЯ ИГРА!",
  "startGame":"НАЧАТЬ ИГРУ",
  "rules":"ПРАВИЛА",
  "settings":"НАСТРОЙКИ",	
  "quit":"ВЫХОД",
  
  "ncat":"СЛОВО",
  "scat":"СЛОВО",
  "at":"СЛОВО",
  "cat":"СЛОВО",
  "back":"СЛОВО",
  
  "sports":[
  "СЛОВО","СЛОВО","СЛОВО","СЛОВО","СЛОВО"
  ],
  "geo":[
  "СЛОВО","СЛОВО","СЛОВО","СЛОВО","СЛОВО"
  ]
}

English is displayed normally, but when using this dictionary, it's just empty.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Trifonov, 2017-07-06
@1Frosty

UTF-8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question