Пример #1
0
    public static T[] FromJson <T>(string jsonStr)
    {
        string newJson = JsonParseUtils.ArrayJsonWrapper(jsonStr);

        JsonParseUtils.Wrapper <T> list = JsonUtility.FromJson <JsonParseUtils.Wrapper <T> >(newJson);

        return(list.items);
    }
Пример #2
0
    // Use this for initialization
    void Awake()
    {
        // Load ----------
        string path = System.IO.Path.Combine(Application.streamingAssetsPath, "menu.json");

        // direct ---
        //items = JsonParseUtils.LoadAndFromJson<Item> (path);

        // stream ---
        System.Text.Encoding encoder = System.Text.Encoding.UTF8;
        string str = fileLoader.LoadStream(path, encoder);

        items = JsonParseUtils.FromJson <Item>(str);

        // Save ----------
        SaveToFile();
    }
Пример #3
0
    //
    public static T[] LoadAndFromJson <T>(string path, Encoding encoder = null)
    {
        using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
            if (encoder == null)
            {
                encoder = Encoding.GetEncoding("Shift_JIS");
            }
            StreamReader sReader = new StreamReader(stream, encoder);
            string       loadStr = sReader.ReadToEnd();

            string newJson = JsonParseUtils.ArrayJsonWrapper(loadStr);
            JsonParseUtils.Wrapper <T> list = JsonUtility.FromJson <JsonParseUtils.Wrapper <T> > (newJson);

            sReader.Close();
            stream.Close();

            return(list.items);
        }
    }