Ejemplo n.º 1
0
        private static JsonToken Read(CharBuffer charBuffer)
        {
            char c = charBuffer.Head();

            while (IsWhiteSpace(c) && charBuffer.HasMore())
            {
                charBuffer.Next();
                if (charBuffer.HasMore())
                {
                    c = charBuffer.Head();
                }
                else
                {
                    return(null);
                }
            }

            switch (c)
            {
            case '{':
                return(new JsonToken(JsonToken.TokenType.BeginObject, charBuffer.Next()));

            case '}':
                return(new JsonToken(JsonToken.TokenType.EndObject, charBuffer.Next()));

            case '[':
                return(new JsonToken(JsonToken.TokenType.BeginArray, charBuffer.Next()));

            case ']':
                return(new JsonToken(JsonToken.TokenType.EndArray, charBuffer.Next()));

            case ',':
                return(new JsonToken(JsonToken.TokenType.SepComma, charBuffer.Next()));

            case ':':
                return(new JsonToken(JsonToken.TokenType.SepColon, charBuffer.Next()));

            case 'n':
                return(new JsonToken(JsonToken.TokenType.Null, ReadNull(charBuffer)));

            case 't':
            case 'f':
                return(new JsonToken(JsonToken.TokenType.Boolean, ReadBoolean(charBuffer)));

            case '"':
                return(new JsonToken(JsonToken.TokenType.String, ReadString(charBuffer)));

            case '-':
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
            case '.':
                return(new JsonToken(JsonToken.TokenType.Number, ReadNumber(charBuffer)));

            default:
                ThrowHelper.Throw("unknown char :" + c);
                break;
            }
            return(null);
        }