Example #1
0
        JsonNode ParseArray(JsonTokenizer tokenizer)
        {
            var res = new JsonNode();

            res.MakeArray();
            bool needSep = false;

            while (true)
            {
                tokenizer.ReadNext();

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

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

                    tokenizer.ReadNext();
                }

                JsonNode value = ParseValue(tokenizer);

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

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

            res.MakeObject();
            bool needSep = false;

            while (true)
            {
                tokenizer.ReadNext();

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

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

                    tokenizer.ReadNext();
                }

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

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

                string field = tokenizer.Token;

                tokenizer.ReadColon();
                tokenizer.ReadNext();

                JsonNode value = ParseValue(tokenizer);

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

                needSep = true;
            }
        }