Ejemplo n.º 1
0
    public IEnumerator LoadJSONData(string fileName, JSON_TYPE jsonType)
    {
        string path = Application.streamingAssetsPath;
        string fullPath;

        fullPath = PathCorrection(path, fileName);
        Debug.Log("Full Path : " + fullPath);

        UnityWebRequest request = UnityWebRequest.Get(fullPath);

        yield return(request.SendWebRequest());

        if (request.isHttpError || request.isNetworkError)
        {
            Debug.Log("Request Error : " + request.error);
            yield break;
        }

        string downloadedText = request.downloadHandler.text;

        Debug.Log(downloadedText);

        if (jsonType == JSON_TYPE.QUIZ)
        {
            QuizJSONData jsonData = TryParseQuizJSONData(downloadedText);
            this.jsonData.AddQuizData(jsonData);
        }
        else if (jsonType == JSON_TYPE.MATERI)
        {
            MateriJSONData jsonData = TryParseMateriJSONData(downloadedText);
            this.jsonData.AddMateriData(jsonData);
        }

        //SceneLoader.instance.LoadScene(SCENE.MENU);
    }
Ejemplo n.º 2
0
        /*<< Having read the sheet by one line, convert jsontype */
        JSON_TYPE GetJsonType(int rowIndex, JSON_TYPE lastType)
        {
            if (_sheet == null)
            {
                return(JSON_TYPE.ERROR);
            }

            IRow rowInfo = _sheet.GetRow(rowIndex);

            if (rowInfo == null)
            {
                return(JSON_TYPE.ERROR);
            }

            ICell CellInfo = rowInfo.GetCell(0);

            if (CellInfo == null)
            {
                return(JSON_TYPE.ERROR);
            }

            string jsonType = "";

            if (CellInfo.CellType == CellType.Numeric)
            {
                jsonType = CellInfo.NumericCellValue.ToString();
            }
            else
            {
                jsonType = CellInfo.StringCellValue;
            }

            if (string.IsNullOrEmpty(jsonType))
            {
                return(JSON_TYPE.ERROR);
            }

            jsonType = jsonType.ToUpper();

            foreach (JSON_TYPE type in Enum.GetValues(typeof(JSON_TYPE)))
            {
                if (jsonType.Equals(type.ToString()))
                {
                    return(type);
                }
            }

            if (lastType == JSON_TYPE.JSON_TABLE_START)
            {
                return(JSON_TYPE.JSON_TABLE_FIELD);
            }
            if (lastType == JSON_TYPE.JSON_TABLE_FIELD || lastType == JSON_TYPE.JSON_TABLE_VALUE)
            {
                return(JSON_TYPE.JSON_TABLE_VALUE);
            }

            return(JSON_TYPE.ERROR);
        }
Ejemplo n.º 3
0
        public void AddFieldInfo(JSON_TYPE type, string fieldName, string value)
        {
            JsonField field = new JsonField();

            field.jsonType  = type;
            field.value     = value;
            field.fieldName = fieldName;
            jsonFieldList.Add(field);
        }
Ejemplo n.º 4
0
 private static PARSE_RESULT ParseLiteral(Context c, Value v, string literal, JSON_TYPE type)
 {
     for (int i = 0; i < literal.Length; i++)
     {
         if (c.index + i >= c.json.Length || c.json[c.index + i] != literal[i])
         {
             return(PARSE_RESULT.INVALID_VALUE);
         }
     }
     c.index += literal.Length;
     v.type   = type;
     return(PARSE_RESULT.OK);
 }
Ejemplo n.º 5
0
        /**< how to read json as table , How to read from Excel into jsontype */
        void LoadFieldInfo()
        {
            JSON_TYPE type  = GetJsonType(0, JSON_TYPE.ERROR);
            int       index = 0;

            if (type == JSON_TYPE.JSON_OUTPUT)
            {
                IRow  rowInfo   = _sheet.GetRow(0);
                ICell cellField = rowInfo.GetCell(1);
                if (cellField != null)
                {
                    outputName = cellField.StringCellValue;
                }

                index = 1;
                type  = GetJsonType(1, JSON_TYPE.ERROR);
            }
            if (type == JSON_TYPE.JSON_VERSION)
            {
                IRow  rowInfo   = _sheet.GetRow(index);
                ICell cellField = rowInfo.GetCell(1);
                if (cellField != null)
                {
                    version = cellField.StringCellValue;
                }

                index = index + 1;
                type  = GetJsonType(index, JSON_TYPE.ERROR);
                AddFieldInfo(JSON_TYPE.JSON_VALUE, "Version", version);
            }
            if (type == JSON_TYPE.ERROR)
            {
                AddFieldInfo(JSON_TYPE.JSON_TABLE_START, "", sheetName);
                LoadFieldInfoByExcel(JSON_TYPE.JSON_TABLE_START, index);
                AddFieldInfo(JSON_TYPE.JSON_TABLE_END, "", "");
            }
            else
            {
                AddFieldInfo(JSON_TYPE.JSON_START, "RES_NAME", sheetName);
                LoadFieldInfoByExcel(JSON_TYPE.ERROR, index);
                AddFieldInfo(JSON_TYPE.JSON_END, "", "");
            }
        }
Ejemplo n.º 6
0
 public JSON_VALUE(bool b)
 {
     _num = b ? 1 : 0; _obj = null; _hash = b ? 1 : 0; _type = JSON_TYPE.Bool;
 }
Ejemplo n.º 7
0
 public JSON_VALUE(string str)
 {
     _num = 0; _obj = str; _hash = str.GetHashCode(); _type = JSON_TYPE.String;
 }
Ejemplo n.º 8
0
 public JSON_VALUE(Dictionary <string, JSON_VALUE> obj)
 {
     _num = 0; _obj = obj; _hash = obj.GetHashCode(); _type = JSON_TYPE.Object;
 }
Ejemplo n.º 9
0
 public JSON_VALUE(List <JSON_VALUE> array)
 {
     _num = 0; _obj = array; _hash = array.GetHashCode(); _type = JSON_TYPE.Array;
 }
Ejemplo n.º 10
0
 public JSON_VALUE(int number)
 {
     _num = number; _obj = null; _hash = number; _type = JSON_TYPE.Number;
 }
Ejemplo n.º 11
0
 public JSON_VALUE(double number)
 {
     _num = number; _obj = null; _hash = Convert.ToInt32(number); _type = JSON_TYPE.Number;
 }
Ejemplo n.º 12
0
        bool LoadFieldInfoByExcel(JSON_TYPE lastType, int index = 0)
        {
            if (_sheet == null)
            {
                return(false);
            }

            List <string> tableField = new List <string>();

            for (int row = index; row <= _sheet.LastRowNum; row++)
            {
                JSON_TYPE type = GetJsonType(row, lastType);

                if (type != JSON_TYPE.ERROR)
                {
                    lastType = type;
                }

                IRow rowInfo = _sheet.GetRow(row);

                if (rowInfo == null)
                {
                    return(false);
                }

                if (type == JSON_TYPE.JSON_ARRAY_START || type == JSON_TYPE.JSON_ARRAY_END || type == JSON_TYPE.JSON_TABLE_END ||
                    type == JSON_TYPE.JSON_START || type == JSON_TYPE.JSON_END)
                {
                    string value = "";

                    ICell cellField = rowInfo.GetCell(1);
                    if (cellField != null)
                    {
                        value = cellField.StringCellValue;
                    }
                    else
                    {
                        if (type == JSON_TYPE.JSON_ARRAY_START || type == JSON_TYPE.JSON_TABLE_START)
                        {
                            CustomEditorTools.DisplayNoticeDialog("Warning Sheet : " + sheetName,
                                                                  "table and field names array is required. If the field name is not difficult to use and accessible to JSON.");
                        }
                    }

                    AddFieldInfo(type, "", value);
                }

                if (type == JSON_TYPE.JSON_VALUE)
                {
                    ICell cellField = rowInfo.GetCell(1);
                    if (cellField == null)
                    {
                        return(false);
                    }

                    string field = cellField.StringCellValue;

                    ICell cellValue = rowInfo.GetCell(2);

                    if (cellValue == null)
                    {
                        return(false);
                    }

                    if (cellValue.CellType == CellType.Numeric)
                    {
                        AddFieldInfo(JSON_TYPE.JSON_VALUE, field, cellValue.NumericCellValue.ToString());
                    }
                    else
                    {
                        AddFieldInfo(JSON_TYPE.JSON_VALUE, field, cellValue.StringCellValue);
                    }
                }

                if (type == JSON_TYPE.JSON_TABLE_START)
                {
                    ICell cell = rowInfo.GetCell(1);
                    if (cell == null)
                    {
                        return(false);
                    }
                    AddFieldInfo(type, "", cell.StringCellValue);
                }

                if (type == JSON_TYPE.JSON_TABLE_FIELD)
                {
                    for (int col = 0; col < rowInfo.LastCellNum; col++)
                    {
                        ICell cell = rowInfo.GetCell(col);
                        if (cell == null)
                        {
                            return(false);
                        }
                        tableField.Add(cell.StringCellValue);
                    }
                }

                if (type == JSON_TYPE.JSON_TABLE_VALUE)
                {
                    AddFieldInfo(JSON_TYPE.JSON_START, "", "");
                    for (int col = 0; col < rowInfo.LastCellNum; col++)
                    {
                        ICell cell = rowInfo.GetCell(col);
                        if (cell == null)
                        {
                            return(false);
                        }

                        if (cell.CellType == CellType.Numeric)
                        {
                            AddFieldInfo(JSON_TYPE.JSON_VALUE, tableField[col], cell.NumericCellValue.ToString());
                        }
                        else
                        {
                            AddFieldInfo(JSON_TYPE.JSON_VALUE, tableField[col], cell.StringCellValue);
                        }
                    }

                    AddFieldInfo(JSON_TYPE.JSON_END, "", "");
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
 public JsonField()
 {
     jsonType  = JSON_TYPE.JSON_START;
     value     = "";
     fieldName = "";
 }