Esempio n. 1
0
        /// <summary>
        /// Construct a JSONArray from a JSONTokener.
        /// </summary>
        /// <param name="x">A JSONTokener</param>
        public JSONArray(JSONTokener x) : this()
        {
            if (x.nextClean() != '[')
            {
                throw new Exception("A JSONArray must start with '['");
            }
            if (x.nextClean() == ']')
            {
                return;
            }
            x.back();
            while (true)
            {
                myArrayList.Add(x.nextObject());
                switch (x.nextClean())
                {
                case ',':
                    if (x.nextClean() == ']')
                    {
                        return;
                    }
                    x.back();
                    break;

                case ']':
                    return;

                default:
                    throw new Exception("Expected a ',' or ']'");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Construct a JSONObject from a JSONTokener.
        /// </summary>
        /// <param name="x">A JSONTokener object containing the source string.</param>
        public JSONObject(JSONTokener x) : this()
        {
            char   c;
            string key;

            if (x.next() == '%')
            {
                x.unescape();
            }
            x.back();
            if (x.nextClean() != '{')
            {
                throw new Exception("A JSONObject must begin with '{'");
            }
            while (true)
            {
                c = x.nextClean();
                switch (c)
                {
                case (char)0:
                    throw new Exception("A JSONObject must end with '}'");

                case '}':
                    return;

                default:
                    x.back();
                    key = x.nextObject().ToString();
                    break;
                }
                if (x.nextClean() != ':')
                {
                    throw new Exception("Expected a ':' after a key");
                }
                object obj = x.nextObject();
                myHashMap.Add(key, obj);
                myKeyIndexList.Add(key);
                switch (x.nextClean())
                {
                case ',':
                    if (x.nextClean() == '}')
                    {
                        return;
                    }
                    x.back();
                    break;

                case '}':
                    return;

                default:
                    throw new Exception("Expected a ',' or '}'");
                }
            }
        }