コード例 #1
0
        private static IDictionary <object, object> ParseObject(char[] json, ref int index, ref bool success)
        {
            //  IDictionary<string, object> dictionary = new JsonObject();
            IDictionary <object, object> dictionary = new Dictionary <object, object>();

            SimpleJsonTool.NextToken(json, ref index);
            bool flag = false;
            IDictionary <object, object> result;

            while (!flag)
            {
                int num = SimpleJsonTool.LookAhead(json, index);
                if (num != 0)
                {
                    if (num == 6)
                    {
                        SimpleJsonTool.NextToken(json, ref index);
                    }
                    else
                    {
                        if (num == 2)
                        {
                            SimpleJsonTool.NextToken(json, ref index);
                            result = dictionary;
                            return(result);
                        }
                        //string key = SimpleJsonTool.ParseString(json, ref index, ref success);
                        object key = SimpleJsonTool.ParseValue(json, ref index, ref success);
                        if (!success)
                        {
                            success = false;
                            result  = null;
                            return(result);
                        }
                        num = SimpleJsonTool.NextToken(json, ref index);
                        if (num != 5)
                        {
                            success = false;
                            result  = null;
                            return(result);
                        }
                        object value = SimpleJsonTool.ParseValue(json, ref index, ref success);
                        if (!success)
                        {
                            success = false;
                            result  = null;
                            return(result);
                        }
                        dictionary[key] = value;
                    }
                    continue;
                }
                success = false;
                result  = null;
                return(result);
            }
            result = dictionary;
            return(result);
        }
コード例 #2
0
        public static bool TryDeserializeObject(string json, out object obj)
        {
            bool result = true;

            if (json != null)
            {
                char[] json2 = json.ToCharArray();
                int    num   = 0;
                obj = SimpleJsonTool.ParseValue(json2, ref num, ref result);
            }
            else
            {
                obj = null;
            }
            return(result);
        }
コード例 #3
0
        private static JsonArray ParseArray(char[] json, ref int index, ref bool success)
        {
            JsonArray jsonArray = new JsonArray();

            SimpleJsonTool.NextToken(json, ref index);
            bool      flag = false;
            JsonArray result;

            while (!flag)
            {
                int num = SimpleJsonTool.LookAhead(json, index);
                if (num != 0)
                {
                    if (num == 6)
                    {
                        SimpleJsonTool.NextToken(json, ref index);
                    }
                    else
                    {
                        if (num == 4)
                        {
                            SimpleJsonTool.NextToken(json, ref index);
                            break;
                        }
                        object item = SimpleJsonTool.ParseValue(json, ref index, ref success);
                        if (!success)
                        {
                            result = null;
                            return(result);
                        }
                        jsonArray.Add(item);
                    }
                    continue;
                }
                success = false;
                result  = null;
                return(result);
            }
            result = jsonArray;
            return(result);
        }