Пример #1
0
    public void UpdateTable()
    {
        RemoveAllCells();

        string jsonString = File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "JsonChallenge.json"));

        try
        {
            TableData parsedTable = TableData.FromJson(jsonString);

            title.text = parsedTable.title;

            table.GetComponent <GridLayoutGroup>().constraintCount = parsedTable.columnHeaders.Length;

            foreach (string columnName in parsedTable.columnHeaders)
            {
                Text newHeader = Instantiate(headerCell, this.table.transform);
                newHeader.text = columnName;
            }


            foreach (Dictionary <string, string> row in parsedTable.data)
            {
                foreach (string columnName in parsedTable.columnHeaders)
                {
                    Text newCell = Instantiate(tableCell, table.transform);
                    newCell.text = row[columnName];
                }
            }
        }
        catch (System.Exception e)
        {
            title.text = e.Message;
        }
    }