コード例 #1
0
        } // End of ImplIsString (...)

        protected virtual ArrayList ImplParseArray(
            out JsonScanner.TokenBase endToken,
            TextReader textReader)
        {
            endToken = JsonScanner.EofToken.Singleton;

            if (textReader == null)
            {
                return(null);
            }

            JsonScanner.NumericToken numericToken = null;
            ArrayList retVal = new ArrayList();

            //JsonScanner.StringToken     strToken      = null;
            JsonScanner.TokenBase token = null;
            Object value = null;
            IValueProvider <Object> valueProvider = null;

            do
            {
                token = JsonScanner.Singleton.ScanToken(textReader);

                if (token == JsonScanner.SquaredOpenToken.Singleton)
                {
                }
                else if (token == JsonScanner.CurlyOpenToken.Singleton)
                {
                    value = ImplParseUnit(out token, textReader);

                    if (token != JsonScanner.CurlyCloseToken.Singleton)
                    {
                        return(null);
                    }
                }
                else if ((numericToken = token as JsonScanner.NumericToken) != null)
                {
                    value = new NumericStringValue(numericToken.Value);
                }
                else if ((valueProvider = token as IValueProvider <Object>) != null)
                {
                    value = valueProvider.Value;
                }
                else
                {
                    return(null); // Unespected token
                }
                retVal.Add(value);

                token = JsonScanner.Singleton.ScanToken(textReader);
            }while (token == JsonScanner.CommaToken.Singleton);

            endToken = token;

            return(retVal);
        } // End of ImplParseArray (...)
コード例 #2
0
        } // End of ImplParseUnit (...)

        protected override IValueUnit ImplRead(TextReader textReader)
        {
            IValueUnit retVal = null;

            JsonScanner.TokenBase token = JsonScanner.Singleton.ScanToken(textReader);

            if (token != JsonScanner.CurlyOpenToken.Singleton)
            {
                return(null); // Unespected token
            }
            retVal = ImplParseUnit(out token, textReader);

            return(token == JsonScanner.CurlyCloseToken.Singleton ? retVal : null);
        } // End of ImplRead (...)
コード例 #3
0
        } // End of ImplParseArray (...)

        protected virtual IValueUnit ImplParseUnit(
            out JsonScanner.TokenBase endToken,
            TextReader textReader)
        {
            endToken = JsonScanner.EofToken.Singleton;

            if (textReader == null)
            {
                return(null);
            }

            JsonScanner.NumericToken numericToken = null;
            String key = null;

            JsonScanner.TokenBase token  = null;
            ValueUnit             retVal = new ValueUnit();

            JsonScanner.StringToken strToken = null;
            Object value = null;
            IValueProvider <Object> valueProvider = null;

            do
            {
                token = JsonScanner.Singleton.ScanToken(textReader);

                if ((strToken = token as JsonScanner.StringToken) == null)
                {
                    return(null); // Unespected token
                }
                else
                {
                    key = strToken.Value;
                }

                token = JsonScanner.Singleton.ScanToken(textReader);

                if (token != JsonScanner.ColonToken.Singleton)
                {
                    return(null); // Unespected token
                }
                token = JsonScanner.Singleton.ScanToken(textReader);

                if ((strToken = token as JsonScanner.StringToken) != null)
                {
                    value = strToken.Value;
                }
                else if (token == JsonScanner.SquaredOpenToken.Singleton)
                {
                    value = ImplParseArray(out token, textReader);

                    if (token == JsonScanner.SquaredCloseToken.Singleton)
                    {
                        value = new ValueSequence((IEnumerable)value);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (token == JsonScanner.CurlyOpenToken.Singleton)
                {
                    value = ImplParseUnit(out token, textReader);

                    if (token != JsonScanner.CurlyCloseToken.Singleton)
                    {
                        return(null);
                    }
                }
                else if ((numericToken = token as JsonScanner.NumericToken) != null)
                {
                    value = new NumericStringValue(numericToken.Value);
                }
                else if ((valueProvider = token as IValueProvider <Object>) != null)
                {
                    value = valueProvider.Value;
                }
                else
                {
                    return(null); // Unespected token
                }
                retVal.Add(new ValueItem(key, value));

                token = JsonScanner.Singleton.ScanToken(textReader);
            }while (token == JsonScanner.CommaToken.Singleton);

            endToken = token;

            return(retVal);
        } // End of ImplParseUnit (...)