示例#1
0
        // Token: 0x06004B2F RID: 19247 RVA: 0x00148FE8 File Offset: 0x001471E8
        private static string ParseString(string str, ref int startPosition)
        {
            if (str[startPosition] != '"' || startPosition + 1 >= str.Length)
            {
                Object.Fail('"', startPosition);
                return(null);
            }
            int num = str.IndexOf('"', startPosition + 1);

            if (num <= startPosition)
            {
                Object.Fail('"', startPosition + 1);
                return(null);
            }
            while (str[num - 1] == '\\')
            {
                num = str.IndexOf('"', num + 1);
                if (num <= startPosition)
                {
                    Object.Fail('"', startPosition + 1);
                    return(null);
                }
            }
            string result = string.Empty;

            if (num > startPosition + 1)
            {
                result = str.Substring(startPosition + 1, num - startPosition - 1);
            }
            startPosition = num;
            return(result);
        }
示例#2
0
 // Token: 0x06004B31 RID: 19249 RVA: 0x0014915C File Offset: 0x0014735C
 private static Object Fail(char expected, int position)
 {
     return(Object.Fail(new string(expected, 1), position));
 }
示例#3
0
        // Token: 0x06004B2D RID: 19245 RVA: 0x00148854 File Offset: 0x00146A54
        public static Object Parse(string jsonString)
        {
            if (string.IsNullOrEmpty(jsonString))
            {
                return(null);
            }
            Value         value = null;
            List <string> list  = new List <string>();

            Object.ParsingState parsingState = Object.ParsingState.Object;
            for (int i = 0; i < jsonString.Length; i++)
            {
                i = Object.SkipWhitespace(jsonString, i);
                switch (parsingState)
                {
                case Object.ParsingState.Object:
                {
                    if (jsonString[i] != '{')
                    {
                        return(Object.Fail('{', i));
                    }
                    Value value2 = new Object();
                    if (value != null)
                    {
                        value2.Parent = value;
                    }
                    value        = value2;
                    parsingState = Object.ParsingState.Key;
                    break;
                }

                case Object.ParsingState.Array:
                {
                    if (jsonString[i] != '[')
                    {
                        return(Object.Fail('[', i));
                    }
                    Value value3 = new Array();
                    if (value != null)
                    {
                        value3.Parent = value;
                    }
                    value        = value3;
                    parsingState = Object.ParsingState.Value;
                    break;
                }

                case Object.ParsingState.EndObject:
                {
                    if (jsonString[i] != '}')
                    {
                        return(Object.Fail('}', i));
                    }
                    if (value.Parent == null)
                    {
                        return(value.Obj);
                    }
                    ValueType type = value.Parent.Type;
                    if (type != ValueType.Object)
                    {
                        if (type != ValueType.Array)
                        {
                            return(Object.Fail("valid object", i));
                        }
                        value.Parent.Array.Add(new Value(value.Obj));
                    }
                    else
                    {
                        value.Parent.Obj.values[list.Pop <string>()] = new Value(value.Obj);
                    }
                    value        = value.Parent;
                    parsingState = Object.ParsingState.ValueSeparator;
                    break;
                }

                case Object.ParsingState.EndArray:
                {
                    if (jsonString[i] != ']')
                    {
                        return(Object.Fail(']', i));
                    }
                    if (value.Parent == null)
                    {
                        return(value.Obj);
                    }
                    ValueType type = value.Parent.Type;
                    if (type != ValueType.Object)
                    {
                        if (type != ValueType.Array)
                        {
                            return(Object.Fail("valid object", i));
                        }
                        value.Parent.Array.Add(new Value(value.Array));
                    }
                    else
                    {
                        value.Parent.Obj.values[list.Pop <string>()] = new Value(value.Array);
                    }
                    value        = value.Parent;
                    parsingState = Object.ParsingState.ValueSeparator;
                    break;
                }

                case Object.ParsingState.Key:
                    if (jsonString[i] == '}')
                    {
                        i--;
                        parsingState = Object.ParsingState.EndObject;
                    }
                    else
                    {
                        string text = Object.ParseString(jsonString, ref i);
                        if (text == null)
                        {
                            return(Object.Fail("key string", i));
                        }
                        list.Add(text);
                        parsingState = Object.ParsingState.KeyValueSeparator;
                    }
                    break;

                case Object.ParsingState.Value:
                {
                    char c = jsonString[i];
                    if (c == '"')
                    {
                        parsingState = Object.ParsingState.String;
                    }
                    else if (char.IsDigit(c) || c == '-')
                    {
                        parsingState = Object.ParsingState.Number;
                    }
                    else
                    {
                        char c2 = c;
                        switch (c2)
                        {
                        case '[':
                            parsingState = Object.ParsingState.Array;
                            break;

                        default:
                            if (c2 != 'f')
                            {
                                if (c2 == 'n')
                                {
                                    parsingState = Object.ParsingState.Null;
                                    break;
                                }
                                if (c2 != 't')
                                {
                                    if (c2 != '{')
                                    {
                                        return(Object.Fail("beginning of value", i));
                                    }
                                    parsingState = Object.ParsingState.Object;
                                    break;
                                }
                            }
                            parsingState = Object.ParsingState.Boolean;
                            break;

                        case ']':
                            if (value.Type != ValueType.Array)
                            {
                                return(Object.Fail("valid array", i));
                            }
                            parsingState = Object.ParsingState.EndArray;
                            break;
                        }
                    }
                    i--;
                    break;
                }

                case Object.ParsingState.KeyValueSeparator:
                    if (jsonString[i] != ':')
                    {
                        return(Object.Fail(':', i));
                    }
                    parsingState = Object.ParsingState.Value;
                    break;

                case Object.ParsingState.ValueSeparator:
                {
                    char c2 = jsonString[i];
                    if (c2 != ',')
                    {
                        if (c2 != ']')
                        {
                            if (c2 != '}')
                            {
                                return(Object.Fail(", } ]", i));
                            }
                            parsingState = Object.ParsingState.EndObject;
                            i--;
                        }
                        else
                        {
                            parsingState = Object.ParsingState.EndArray;
                            i--;
                        }
                    }
                    else
                    {
                        parsingState = ((value.Type != ValueType.Object) ? Object.ParsingState.Value : Object.ParsingState.Key);
                    }
                    break;
                }

                case Object.ParsingState.String:
                {
                    string text2 = Object.ParseString(jsonString, ref i);
                    if (text2 == null)
                    {
                        return(Object.Fail("string value", i));
                    }
                    ValueType type = value.Type;
                    if (type != ValueType.Object)
                    {
                        if (type != ValueType.Array)
                        {
                            Debug.LogError("Fatal error, current JSON value not valid");
                            return(null);
                        }
                        value.Array.Add(text2);
                    }
                    else
                    {
                        value.Obj.values[list.Pop <string>()] = new Value(text2);
                    }
                    parsingState = Object.ParsingState.ValueSeparator;
                    break;
                }

                case Object.ParsingState.Number:
                {
                    double num = Object.ParseNumber(jsonString, ref i);
                    if (double.IsNaN(num))
                    {
                        return(Object.Fail("valid number", i));
                    }
                    ValueType type = value.Type;
                    if (type != ValueType.Object)
                    {
                        if (type != ValueType.Array)
                        {
                            Debug.LogError("Fatal error, current JSON value not valid");
                            return(null);
                        }
                        value.Array.Add(num);
                    }
                    else
                    {
                        value.Obj.values[list.Pop <string>()] = new Value(num);
                    }
                    parsingState = Object.ParsingState.ValueSeparator;
                    break;
                }

                case Object.ParsingState.Boolean:
                    if (jsonString[i] == 't')
                    {
                        if (jsonString.Length < i + 4 || jsonString[i + 1] != 'r' || jsonString[i + 2] != 'u' || jsonString[i + 3] != 'e')
                        {
                            return(Object.Fail("true", i));
                        }
                        ValueType type = value.Type;
                        if (type != ValueType.Object)
                        {
                            if (type != ValueType.Array)
                            {
                                Debug.LogError("Fatal error, current JSON value not valid");
                                return(null);
                            }
                            value.Array.Add(new Value(true));
                        }
                        else
                        {
                            value.Obj.values[list.Pop <string>()] = new Value(true);
                        }
                        i += 3;
                    }
                    else
                    {
                        if (jsonString.Length < i + 5 || jsonString[i + 1] != 'a' || jsonString[i + 2] != 'l' || jsonString[i + 3] != 's' || jsonString[i + 4] != 'e')
                        {
                            return(Object.Fail("false", i));
                        }
                        ValueType type = value.Type;
                        if (type != ValueType.Object)
                        {
                            if (type != ValueType.Array)
                            {
                                Debug.LogError("Fatal error, current JSON value not valid");
                                return(null);
                            }
                            value.Array.Add(new Value(false));
                        }
                        else
                        {
                            value.Obj.values[list.Pop <string>()] = new Value(false);
                        }
                        i += 4;
                    }
                    parsingState = Object.ParsingState.ValueSeparator;
                    break;

                case Object.ParsingState.Null:
                    if (jsonString[i] == 'n')
                    {
                        if (jsonString.Length < i + 4 || jsonString[i + 1] != 'u' || jsonString[i + 2] != 'l' || jsonString[i + 3] != 'l')
                        {
                            return(Object.Fail("null", i));
                        }
                        ValueType type = value.Type;
                        if (type != ValueType.Object)
                        {
                            if (type != ValueType.Array)
                            {
                                Debug.LogError("Fatal error, current JSON value not valid");
                                return(null);
                            }
                            value.Array.Add(new Value(ValueType.Null));
                        }
                        else
                        {
                            value.Obj.values[list.Pop <string>()] = new Value(ValueType.Null);
                        }
                        i += 3;
                    }
                    parsingState = Object.ParsingState.ValueSeparator;
                    break;
                }
            }
            Debug.LogError("Unexpected end of string");
            return(null);
        }