• 数据转换成JSON类型


    #region ToJson
    /// <summary>
    /// 生成压缩的json 字符串
    /// </summary>
    /// <param name="obj">生成json的对象</param>
    public static string ToJson(object obj)
    {
    return ToJson(obj, false);
    }

    /// <summary>
    /// 生成JSON字符串
    /// </summary>
    /// <param name="obj">生成json的对象</param>
    /// <param name="formatjson">是否格式化</param>
    public static string ToJson(object obj, bool formatjson)
    {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    System.IO.StringWriter sw = new System.IO.StringWriter(sb);

    Newtonsoft.Json.Converters.IsoDateTimeConverter idtc = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
    idtc.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

    Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
    serializer.Converters.Add(idtc);
    Newtonsoft.Json.JsonWriter jw = new Newtonsoft.Json.JsonTextWriter(sw);

    if (formatjson)
    {
    jw.Formatting = Newtonsoft.Json.Formatting.Indented;
    }
    serializer.Serialize(jw, obj);
    return sb.ToString();
    }

    #endregion

  • 相关阅读:
    矩阵图
    博客园评价
    团队冲刺
    团队冲刺
    第二阶段团队冲刺
    团队博客
    团队冲刺
    总结会议
    会议10
    会议09
  • 原文地址:https://www.cnblogs.com/2260827114com/p/7121724.html
Copyright © 2020-2023  润新知