예제 #1
0
        internal void Write(object value, JsonValueType valueType)
        {
            CheckEnd();
            Head();
            if (JsonApi.HasFlag(Stacks.Peek().Stage, JsonTextWriterStage.Key))
            {
                valueType = JsonValueType.String;
            }
            switch (valueType)
            {
            case JsonValueType.Null:
                TextWriter.Write(JsonKeyword.Null);
                break;

            case JsonValueType.Integer:
                TextWriter.Write(value);
                break;

            case JsonValueType.Decimal:
                TextWriter.Write(value);
                if (value.ToString().IndexOf('.') < 0)
                {
                    TextWriter.Write(".0");
                }
                break;

            case JsonValueType.Bool:
                TextWriter.Write(Convert.ToBoolean(value) ? JsonKeyword.True : JsonKeyword.False);
                break;

            case JsonValueType.String:
                WriteString(JsonApi.CancelUnescape(Convert.ToString(value)));
                break;

            case JsonValueType.DateTime:
                DateTime dateTime = Convert.ToDateTime(value);
                WriteString(Config.UTCTime ? dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") : dateTime.ToString());
                break;

            default:
                throw new JsonNotSupportException(valueType);
            }
            Tail();
        }