Ejemplo n.º 1
0
    public static List <T> GetListFromFilepath <T>(string filepath)
    {
        List <T> output       = new List <T>();
        string   contentsJson = "";

        try {
            StreamReader reader = new StreamReader(filepath, Encoding.Default);
            using (reader) {
                contentsJson = reader.ReadToEnd();
                reader.Close();
            }
        } catch (IOException e) {
            Debug.LogError(e.Message);
        } catch (OutOfMemoryException e) {
            Debug.LogError(e.Message);
        } catch (Exception e) {
            Debug.LogError(e.Message);
        }

        T[] contentArray = JsonArrayHelper.FromJson <T>(contentsJson);
        foreach (T obj in contentArray)
        {
            output.Add(obj);
        }

        return(output);
    }
Ejemplo n.º 2
0
    // TODO: Consider moving this to JsonListHelper or other utility class
    private void ReadAndConstructDictionary()
    {
        languageDictionary = new Dictionary <string, string>();
        string rawJson  = "";
        string filepath = Application.dataPath + folderPath + "test_" + language + ".json";

        try {
            StreamReader reader = new StreamReader(filepath, Encoding.Default);
            using (reader) {
                rawJson = reader.ReadToEnd();
                reader.Close();
            }
        } catch (IOException e) {
            Debug.LogError(e.Message);
        } catch (OutOfMemoryException e) {
            Debug.LogError(e.Message);
        } catch (Exception e) {
            Debug.LogError(e.Message);
        }

        TranslatedString[] arrayContents = JsonArrayHelper.FromJson <TranslatedString>(rawJson);
        foreach (TranslatedString pair in arrayContents)
        {
            languageDictionary.Add(pair.key, pair.value);
        }
    }
    public static T[][] FromJson <T>(string json)
    {
        string[] rows   = JsonArrayHelper.FromJson <string>(json);
        T[][]    result = new T[rows.GetLength(0)][];

        for (int i = 0; i < rows.GetLength(0); i++)
        {
            Debug.Log("JSON row(" + i + "): " + rows[i]);

            result[i] = JsonArrayHelper.FromJson <T>(rows[i]);

            Debug.Log("Deserialized row(" + i + "): " + result[i]);
        }

        return(result);
    }