Example #1
0
        ProxyObject DecodeObject()
        {
            var proxy = new ProxyObject();

            // Ditch opening brace.
            json.Read();

            // {
            while (true)
            {
                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (NextToken)
                {
                case Token.None:
                    return(null);

                case Token.Comma:
                    continue;

                case Token.CloseBrace:
                    return(proxy);

                default:
                    // Key
                    string key = DecodeString();
                    if (key == null)
                    {
                        return(null);
                    }

                    // :
                    if (NextToken != Token.Colon)
                    {
                        return(null);
                    }

                    json.Read();

                    // Value
                    proxy.Add(key, DecodeValue());
                    break;
                }
            }
        }
Example #2
0
        ProxyObject DecodeObject()
        {
            ProxyObject obj = new ProxyObject();

            // ditch opening brace
            json.Read();

            // {
            while (true)
            {
                switch (NextToken)
                {
                case TOKEN.NONE:
                    return(null);

                case TOKEN.COMMA:
                    continue;

                case TOKEN.CURLY_CLOSE:
                    return(obj);

                default:
                    // name
                    string name = DecodeString();
                    if (name == null)
                    {
                        return(null);
                    }

                    // :
                    if (NextToken != TOKEN.COLON)
                    {
                        return(null);
                    }
                    json.Read();

                    obj.Add(name, DecodeValue());
                    break;
                }
            }
        }