示例#1
0
        public bool ReadFieldValue(out IJsonNode node)
        {
            var literal = ReadLiteral();

            if (literal != JsonLiteral.Assignment)
            {
                throw UnexpectedJsonException.InObject(literal);
            }

            literal = ReadLiteral();
            switch (literal)
            {
            case JsonLiteral.ObjectBegin:
                node = ReadObject(expectStartToken: false);
                break;

            case JsonLiteral.ArrayBegin:
                node = ReadArray(expectStartToken: false);
                break;

            case JsonLiteral.Quote:
                var value = ReadString(expectStartToken: false);
                node = new JsonString(value);
                break;

            case JsonLiteral.Number:
                node = ReadNumber();
                break;

            case JsonLiteral.Null:
                node = JsonNull.Instance;
                break;

            case JsonLiteral.True:
                node = JsonBool.True;
                break;

            case JsonLiteral.False:
                node = JsonBool.False;
                break;

            case JsonLiteral.Undefined:
                node = JsonUndefined.Instance;
                break;

            default:
                throw UnexpectedJsonException.InObject(literal);
            }
            return(true);
        }
示例#2
0
        public bool ReadFieldName(out string name)
        {
            var literal = ReadLiteral();

            if (literal == JsonLiteral.Comma)
            {
                literal = ReadLiteral();
            }
            if (literal == JsonLiteral.ObjectEnd)
            {
                name = null;
                return(false);
            }
            if (literal != JsonLiteral.Quote)
            {
                throw UnexpectedJsonException.InObject(literal);
            }
            name = ReadString(expectStartToken: false);
            return(true);
        }