Example #1
0
        static SLJsonNode ParseArray(SLJsonTokenizer tokenizer)
        {
            var res = new SLJsonNode();

            res.MakeArray();
            bool needSep = false;

            while (true)
            {
                tokenizer.ReadNext();

                if (tokenizer.SpecialChar == ']')
                {
                    return(res);
                }

                if (needSep)
                {
                    if (tokenizer.SpecialChar != ',')
                    {
                        throw new SLJsonException("Separator expected");
                    }

                    tokenizer.ReadNext();
                }

                SLJsonNode value = ParseValue(tokenizer);

                res.m_Array.Add(value);
                value.AssignParent(res);

                needSep = true;
            }
        }
Example #2
0
        SLJsonNode ParseObject(SLJsonTokenizer tokenizer)
        {
            var res = new SLJsonNode();

            res.MakeObject();
            bool needSep = false;

            while (true)
            {
                tokenizer.ReadNext();

                if (tokenizer.SpecialChar == '}')
                {
                    return(res);
                }

                if (needSep)
                {
                    if (tokenizer.SpecialChar != ',')
                    {
                        throw new SLJsonException("Separator expected");
                    }

                    tokenizer.ReadNext();
                }

                if (tokenizer.HasSpecialChar)
                {
                    throw new SLJsonException("Unexpected token");
                }

                if (!AreUnquotedNamesAllowed && !tokenizer.TokenIsString)
                {
                    throw new SLJsonException("String expected");
                }

                string field = tokenizer.Token;

                tokenizer.ReadNext();
                if (tokenizer.SpecialChar != ':')
                {
                    throw new SLJsonException("Colon expected");
                }

                tokenizer.ReadNext();

                SLJsonNode value = ParseValue(tokenizer);

                res.m_Object[field] = value; // No exception for multiple fields with the same name
                value.AssignParent(res);

                needSep = true;
            }
        }