Пример #1
0
    public static string ConvertToJsonValue(object value)
    {
        if (value == null || Convert.IsDBNull(value) || value is YZModulePermision)
        {
            return("\"\"");
        }

        if (value is Guid)
        {
            return("\"" + Convert.ToString(value) + "\"");
        }

        if (value is string)
        {
            return("\"" + YZJsonHelper.EncodeAttribute(Convert.ToString(value)) + "\"");
        }

        if (value is DateTime)
        {
            DateTime date = (DateTime)value;
            if (date == DateTime.MinValue)
            {
                return("null");
            }

            return(String.Format("new Date({0},{1},{2},{3},{4},{5})",
                                 date.Year,
                                 date.Month - 1,
                                 date.Day,
                                 date.Hour,
                                 date.Minute,
                                 date.Second));
        }

        if (value is byte[])
        {
            return("\"\"");
        }
        //return "\"" + Convert.ToBase64String((byte[])value) + "\"";目前还不支持绑定2进制数据

        //欧洲、印度等国家,小数点会转换为",",这在JavaScript中不会识别,JS识别的是"."
        string rv = Convert.ToString(value, YZJsonHelper.JavaScriptFormat);

        if (value is bool)
        {
            rv = rv.ToLower();
        }

        return(rv);
    }
Пример #2
0
    public static string ConvertToJsonValue(object value)
    {
        if (value == null || Convert.IsDBNull(value))
        {
            return("\"\"");
        }

        if (value is string)
        {
            return("\"" + YZJsonHelper.EncodeAttribute(Convert.ToString(value)) + "\"");
        }

        if (value is DateTime)
        {
            DateTime date = (DateTime)value;
            if (date == DateTime.MinValue)
            {
                return("\"\"");
            }
            return(String.Format("{{\"year\":{0},\"month\":{1},\"day\":{2}}}",
                                 date.Year,
                                 date.Month,
                                 date.Day,
                                 date.Hour,
                                 date.Minute,
                                 date.Second));
        }

        if (value is byte[])
        {
            return("\"\"");
        }
        //return "\"" + Convert.ToBase64String((byte[])value) + "\"";目前还不支持绑定2进制数据

        //欧洲、印度等国家,小数点会转换为",",这在JavaScript中不会识别,JS识别的是"."
        string rv = Convert.ToString(value, YZJsonHelper.JavaScriptFormat);

        if (value is bool)
        {
            rv = rv.ToLower();
        }

        return(rv);
    }