Exemple #1
0
 /// <summary>
 /// Model转为Json字符串
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="model"></param>
 /// <param name="format"></param>
 /// <returns></returns>
 public static string ToJson <T>(this T model, NFinal.Json.DateTimeFormat format = Json.DateTimeFormat.LocalTimeNumber)
 {
     NFinal.IO.StringWriter          sw   = new NFinal.IO.StringWriter();
     NFinal.Json.GetJsonDelegate <T> dele = (NFinal.Json.GetJsonDelegate <T>)NFinal.Json.JsonHelper.GetDelegate(model, format);
     dele(model, sw, format);
     return(sw.ToString());
 }
Exemple #2
0
 /// <summary>
 /// Model集合转为Json字符串
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="modelList"></param>
 /// <param name="format"></param>
 /// <returns></returns>
 public static string ToJson <T>(this IEnumerable <T> modelList, NFinal.Json.DateTimeFormat format = Json.DateTimeFormat.LocalTimeNumber)
 {
     if (modelList == null)
     {
         return("null");
     }
     else
     {
         NFinal.IO.StringWriter          sw   = new NFinal.IO.StringWriter();
         NFinal.Json.GetJsonDelegate <T> dele = null;
         sw.Write("[");
         foreach (T model in modelList)
         {
             if (dele == null)
             {
                 dele = (NFinal.Json.GetJsonDelegate <T>)NFinal.Json.JsonHelper.GetDelegate(model, format);
             }
             else
             {
                 sw.Write(",");
             }
             dele(model, sw, format);
         }
         sw.Write("]");
         return(sw.ToString());
     }
 }
Exemple #3
0
 /// <summary>
 /// 写Json字符串
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="modelList"></param>
 /// <param name="sw"></param>
 /// <param name="format"></param>
 public static void WriteJson <T>(IEnumerable <T> modelList, NFinal.IO.IWriter sw, NFinal.Json.DateTimeFormat format = Json.DateTimeFormat.LocalTimeNumber)
 {
     if (modelList == null)
     {
         sw.Write(Constant.nullString);
     }
     else
     {
         NFinal.Json.GetJsonDelegate <T> dele = null;
         sw.Write("[");
         foreach (T model in modelList)
         {
             if (dele == null)
             {
                 dele = (NFinal.Json.GetJsonDelegate <T>)NFinal.Json.JsonHelper.GetDelegate(model, format);
             }
             else
             {
                 sw.Write(",");
             }
             dele(model, sw, format);
         }
         sw.Write("]");
     }
 }
Exemple #4
0
 /// <summary>
 /// 写Json字符串
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="model"></param>
 /// <param name="sw"></param>
 /// <param name="format"></param>
 public static void WriteJson <T>(T model, NFinal.IO.IWriter sw, NFinal.Json.DateTimeFormat format = Json.DateTimeFormat.LocalTimeNumber)
 {
     NFinal.Json.GetJsonDelegate <T> dele = (NFinal.Json.GetJsonDelegate <T>)NFinal.Json.JsonHelper.GetDelegate(model, format);
     dele(model, sw, format);
 }