コード例 #1
0
        public JSONObject(JSONTokener x)
            : this()
        {
            char   c;
            String key;

            if (x.NextClean() != '{')
            {
                throw x.SyntaxError("A JSONObject text must begin with '{'");
            }
            for (; ;)
            {
                c = x.NextClean();
                switch (c)
                {
                case '\0':
                    throw x.SyntaxError("A JSONObject text must end with '}'");

                case '}':
                    return;

                default:
                    x.Back();
                    key = x.NextValue().ToString();
                    break;
                }

                // The key is followed by ':'.

                c = x.NextClean();
                if (c != ':')
                {
                    throw x.SyntaxError("Expected a ':' after a key");
                }
                this.PutOnce(key, x.NextValue());

                // Pairs are separated by ','.

                switch (x.NextClean())
                {
                case ';':
                case ',':
                    if (x.NextClean() == '}')
                    {
                        return;
                    }
                    x.Back();
                    break;

                case '}':
                    return;

                default:
                    throw x.SyntaxError("Expected a ',' or '}'");
                }
            }
        }
コード例 #2
0
        public JSONArray(JSONTokener x)
            : this()
        {
            if (x.NextClean() != '[')
            {
                throw x.SyntaxError("A JSONArray text must start with '['");
            }
            if (x.NextClean() != ']')
            {
                x.Back();
                for (; ;)
                {
                    if (x.NextClean() == ',')
                    {
                        x.Back();
                        this.myArrayList.Add(JSONObject.NULL);
                    }
                    else
                    {
                        x.Back();
                        this.myArrayList.Add(x.NextValue());
                    }
                    switch (x.NextClean())
                    {
                    case ',':
                        if (x.NextClean() == ']')
                        {
                            return;
                        }
                        x.Back();
                        break;

                    case ']':
                        return;

                    default:
                        throw x.SyntaxError("Expected a ',' or ']'");
                    }
                }
            }
        }