Ejemplo n.º 1
0
        /// <summary>
        /// DataSet转为js的数组形式,若为空,则返回[]
        /// </summary>
        /// <param name="ds">数据源</param>
        /// <returns>json数组</returns>
        public static string ConvertDataSetToArray(System.Data.DataSet ds)
        {
            string str = string.Empty;

            if (null != ds && ds.Tables.Count > 0)
            {
                List <string> strTemp = new List <string>();
                for (int i = 0; i < ds.Tables.Count; i++)
                {
                    strTemp.Add(LitJson.ConvertDataTableToArray(ds.Tables[i]));
                }
                str = String.Join(",", strTemp.ToArray());
            }
            return(string.Format("[{0}]", str));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// List转为数组,若为空,则直接返回[]
        /// </summary>
        /// <param name="lst">数据源</param>
        /// <returns>json数组</returns>
        public static string ConvertListToArray <T>(IList <T> lst)
        {
            string str = string.Empty;

            if (null != lst && lst.Count > 0)
            {
                List <string> strTemp = new List <string>();
                foreach (T m in lst)
                {
                    strTemp.Add(LitJson.ConvertObjectToJson(m));
                }
                str = String.Join(",", strTemp.ToArray());
            }
            return(string.Format("[{0}]", str));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// DataTable转为json
 /// </summary>
 /// <param name="dt">数据源</param>
 /// <param name="jsonName">指定的json key名</param>
 /// <returns>json</returns>
 public static string ConvertDataTableToJson(DataTable dt, string jsonName)
 {
     return(string.Format(@"{{""{0}"":{1}}}", jsonName, LitJson.ConvertDataTableToArray(dt)));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// List转为json
 /// </summary>
 /// <param name="lst">数据源</param>
 /// <param name="jsonName">指定json key名</param>
 /// <returns>json</returns>
 public static string ConvertListToJson <T>(IList <T> lst, string jsonName)
 {
     return(string.Format(@"{{""{0}"":{1}}}", jsonName, LitJson.ConvertListToArray <T>(lst)));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// DataSet转为json
 /// </summary>
 /// <param name="ds">数据源</param>
 /// <param name="jsonName">指定json key名</param>
 /// <returns>json</returns>
 public static string ConvertDataSetToJson(DataSet ds, string jsonName)
 {
     return(string.Format(@"{{""{0}"":{1}}}", jsonName, LitJson.ConvertDataSetToArray(ds)));
 }