예제 #1
0
        private static object ReadValue2(JSONReader jsonReader)
        {
            jsonReader.Read();

            switch (jsonReader.TokenType)
            {
            case JSONToken.Boolean:
                return((bool)jsonReader.Value);

            case JSONToken.Integer:
                return(Convert.ToInt32(jsonReader.Value));

            case JSONToken.String:
                return((string)jsonReader.Value);

            case JSONToken.Float:
                return((double)jsonReader.Value);

            case JSONToken.Null:
                return(null);

            case JSONToken.StartObject:
                Hashtable hash = new Hashtable();

                while (jsonReader.TokenType != JSONToken.EndObject)
                {
                    if (jsonReader.TokenType == JSONToken.PropertyName)
                    {
                        hash[jsonReader.Value] = ReadValue(jsonReader);
                    }
                    else
                    {
                        jsonReader.Read();
                    }
                }

                return(hash);

            case JSONToken.StartArray:
                ArrayList list = new ArrayList();

                while (jsonReader.TokenType != JSONToken.EndArray)
                {
                    if (jsonReader.TokenType == JSONToken.EndArray && jsonReader.Value == null)
                    {
                        break;
                    }

                    list.Add(ReadValue(jsonReader));
                }

                return(list);
            }

            return(null);
        }
예제 #2
0
        private static bool FindNextValue(JSONReader reader)
        {
            switch (reader.TokenType)
            {
            case JSONToken.Boolean:
            case JSONToken.Float:
            case JSONToken.Integer:
            case JSONToken.Null:
            case JSONToken.String:
                return(true);
            }

            while (reader.Read() && reader.TokenType != JSONToken.EndObject)
            {
                switch (reader.TokenType)
                {
                case JSONToken.Boolean:
                case JSONToken.Float:
                case JSONToken.Integer:
                case JSONToken.Null:
                case JSONToken.String:
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        private static bool FindNext(JSONReader reader, JSONToken token)
        {
            if (reader.TokenType == token)
            {
                return(true);
            }

            while (reader.Read() && reader.TokenType != JSONToken.EndObject && reader.TokenType != JSONToken.EndArray)
            {
                if (reader.TokenType == token)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        private static bool FindNext(JSONReader reader, JSONToken token)
        {
            if (reader.TokenType == token)
                return true;

            while (reader.Read() && reader.TokenType != JSONToken.EndObject && reader.TokenType != JSONToken.EndArray) {
                if (reader.TokenType == token)
                    return true;
            }

            return false;
        }
예제 #5
0
        private static object ReadValue2(JSONReader jsonReader)
        {
            jsonReader.Read();

            switch (jsonReader.TokenType) {
                case JSONToken.Boolean:
                    return (bool) jsonReader.Value;

                case JSONToken.Integer:
                    return Convert.ToInt32(jsonReader.Value);

                case JSONToken.String:
                    return (string) jsonReader.Value;

                case JSONToken.Float:
                    return (double) jsonReader.Value;

                case JSONToken.Null:
                    return null;

                case JSONToken.StartObject:
                    Hashtable hash = new Hashtable();

                    while (jsonReader.TokenType != JSONToken.EndObject) {
                        if (jsonReader.TokenType == JSONToken.PropertyName)
                            hash[jsonReader.Value] = ReadValue(jsonReader);
                        else
                            jsonReader.Read();
                    }

                    return hash;

                case JSONToken.StartArray:
                    ArrayList list = new ArrayList();

                    while (jsonReader.TokenType != JSONToken.EndArray) {
                        if (jsonReader.TokenType == JSONToken.EndArray && jsonReader.Value == null)
                            break;

                        list.Add(ReadValue(jsonReader));
                    }

                    return list;
            }

            return null;
        }
예제 #6
0
        /*		private static void Debug(string str) {
            System.Web.HttpContext.Current.Trace.Write(str);
        }*/
        private static object ReadValue(JSONReader reader)
        {
            Stack parents = new Stack();
            object cur = null;
            string key = null;
            object obj;

            while (reader.Read()) {
                //Debug(reader.ToString());

                switch (reader.TokenType) {
                    case JSONToken.Boolean:
                    case JSONToken.Integer:
                    case JSONToken.String:
                    case JSONToken.Float:
                    case JSONToken.Null:
                        if (cur is Hashtable) {
                            //Debug(key + "=" + reader.ToString());
                            ((Hashtable) cur)[key] = reader.Value;
                        } else if (cur is ArrayList)
                            ((ArrayList) cur).Add(reader.Value);
                        else
                            return reader.Value;

                        break;

                    case JSONToken.PropertyName:
                        key = (string) reader.Value;
                        break;

                    case JSONToken.StartArray:
                    case JSONToken.StartObject:
                        if (reader.TokenType == JSONToken.StartObject)
                            obj = new Hashtable();
                        else
                            obj = new ArrayList();

                        if (cur is Hashtable) {
                            //Debug(key + "=" + reader.ToString());
                            ((Hashtable) cur)[key] = obj;
                        } else if (cur is ArrayList)
                            ((ArrayList) cur).Add(obj);

                        parents.Push(cur);
                        cur = obj;

                        break;

                    case JSONToken.EndArray:
                    case JSONToken.EndObject:
                        obj = parents.Pop();

                        if (obj != null)
                            cur = obj;

                        break;
                }
            }

            return cur;
        }
예제 #7
0
        private static bool FindNextValue(JSONReader reader)
        {
            switch (reader.TokenType) {
                case JSONToken.Boolean:
                case JSONToken.Float:
                case JSONToken.Integer:
                case JSONToken.Null:
                case JSONToken.String:
                    return true;
            }

            while (reader.Read() && reader.TokenType != JSONToken.EndObject) {
                switch (reader.TokenType) {
                    case JSONToken.Boolean:
                    case JSONToken.Float:
                    case JSONToken.Integer:
                    case JSONToken.Null:
                    case JSONToken.String:
                        return true;
                }
            }

            return false;
        }
예제 #8
0
/*		private static void Debug(string str) {
 *                      System.Web.HttpContext.Current.Trace.Write(str);
 *              }*/

        private static object ReadValue(JSONReader reader)
        {
            Stack  parents = new Stack();
            object cur     = null;
            string key     = null;
            object obj;

            while (reader.Read())
            {
                //Debug(reader.ToString());

                switch (reader.TokenType)
                {
                case JSONToken.Boolean:
                case JSONToken.Integer:
                case JSONToken.String:
                case JSONToken.Float:
                case JSONToken.Null:
                    if (cur is Hashtable)
                    {
                        //Debug(key + "=" + reader.ToString());
                        ((Hashtable)cur)[key] = reader.Value;
                    }
                    else if (cur is ArrayList)
                    {
                        ((ArrayList)cur).Add(reader.Value);
                    }
                    else
                    {
                        return(reader.Value);
                    }

                    break;

                case JSONToken.PropertyName:
                    key = (string)reader.Value;
                    break;

                case JSONToken.StartArray:
                case JSONToken.StartObject:
                    if (reader.TokenType == JSONToken.StartObject)
                    {
                        obj = new Hashtable();
                    }
                    else
                    {
                        obj = new ArrayList();
                    }

                    if (cur is Hashtable)
                    {
                        //Debug(key + "=" + reader.ToString());
                        ((Hashtable)cur)[key] = obj;
                    }
                    else if (cur is ArrayList)
                    {
                        ((ArrayList)cur).Add(obj);
                    }

                    parents.Push(cur);
                    cur = obj;

                    break;

                case JSONToken.EndArray:
                case JSONToken.EndObject:
                    obj = parents.Pop();

                    if (obj != null)
                    {
                        cur = obj;
                    }

                    break;
                }
            }

            return(cur);
        }