全球彩票平台_全球彩票注册平台|官网下载地址

热门关键词: 全球彩票平台,全球彩票注册平台,全球彩官网下载地址

【全球彩票注册平台】MVC项目开发之统计图echa

asp.net MVC项目开发之统计图echarts后台数据的处理(三),mvcecharts

前台显示的东西,有相应的文档很容易修改,后台传递数据方式才是我们最关心的

首先要记住,我们一步数据使用的是post,那么后台代码我们要给方法加上 [HttpPost]注解

不然异步没有效果

下面上代码,为了节省时间,字段变量的命名,我用的是英文1,2,3,不要见怪哦

全球彩票注册平台 1 public ActionResult GetMarriageList(int areaId, int level) { List<VwAllPersonInfoModel> allPerList = new List<VwAllPersonInfoModel>(); IVwAllPersonInfoService allPerService = LoadService<IVwAllPersonInfoService>(); Dictionary<string, Object> json = new Dictionary<string, Object>(); DdlDataSrc ddl = new DdlDataSrc(); DataTable dt = new DataTable(); Criteria c = new Criteria(); StringBuilder sb = new StringBuilder(); ddl.getAllChildAreaIds(sb, areaId); #region 根据区域把获取的数据放入json int one = 0; int two = 0; int three = 0; int four = 0; if (level == 3) { c.AddWhere("AreaId", areaId); allPerList = allPerService.GetAllVwAllPersonInfoModel(c); } else if (level != 0) { string str = sb.Remove(sb.Length - 1, 1).ToString(); dt = allPerService.GetAllPersonInfoCharts(str, 0, 0); allPerList = (List<VwAllPersonInfoModel>)ModelConvertHelper<VwAllPersonInfoModel>.ConvertToModel(dt); } if (allPerList.Count != 0) { for (int i = 0; i < allPerList.Count; i ) { switch (allPerList[i].MaticalStatus)//婚姻状况 { case 1: one; break; case 2: two; break; case 3: three; break; case 4: four; break; } } json.Add("未婚", one); json.Add("已婚有配偶", two); json.Add("离婚", three); json.Add("丧偶", four); } else { json.Add("暂无数据", 1); } #endregion return Json(json); } View Code 

 这里使用 Dictionary<string, Object> json = new Dictionary<string, Object>();Dictionary的结构是这样的:Dictionary<[key], [value]>提供快速的键值查找的方式,把输入异步给统计图。

如果数据是单选的,可以使用switch进行判断,如果是多选的话,请使用if进行判断。分享出来希望能帮到大家,不足的地方,可以留言,共同进步

MVC项目开发之统计图echarts后台数据的处理(三),mvcecharts 前台显示的东西,有相应的文档很容易修改,后台传递数据方式才是我们...

print?/// <summary>  
 /// List转成json  
 /// </summary>  
 /// <typeparam name="T"></typeparam>  
 /// <param name="jsonName"></param>  
 /// <param name="list"></param>  
 /// <returns></returns>  
 public static string ListToJson<T>(IList<T> list, string jsonName) 
 { 
     StringBuilder Json = new StringBuilder(); 
     if (string.IsNullOrEmpty(jsonName)) 
         jsonName = list[0].GetType().Name; 
     Json.Append("{"" jsonName "":["); 
     if (list.Count > 0) 
     { 
         for (int i = 0; i < list.Count; i ) 
         { 
             T obj = Activator.CreateInstance<T>(); 
             PropertyInfo[] pi = obj.GetType().GetProperties(); 
             Json.Append("{"); 
             for (int j = 0; j < pi.Length; j ) 
             { 
                 Type type = pi[j].GetValue(list[i], null).GetType(); 
                 Json.Append(""" pi[j].Name.ToString() "":" StringFormat(pi[j].GetValue(list[i], null).ToString(), type)); 
 
                 if (j < pi.Length - 1) 
                 { 
                     Json.Append(","); 
                 } 
             } 
             Json.Append("}"); 
             if (i < list.Count - 1) 
             { 
                 Json.Append(","); 
             } 
         } 
     } 
     Json.Append("]}"); 
     return Json.ToString(); 
 } 
 
 /// <summary>  
 /// List转成json  
 /// </summary>  
 /// <typeparam name="T"></typeparam>  
 /// <param name="list"></param>  
 /// <returns></returns>  
 public static string ListToJson<T>(IList<T> list) 
 { 
     object obj = list[0]; 
     return ListToJson<T>(list, obj.GetType().Name); 
 } 
 
 /// <summary>  
 /// 对象转换为Json字符串  
 /// </summary>  
 /// <param name="jsonObject">对象</param>  
 /// <returns>Json字符串</returns>  
 public static string ToJson(object jsonObject) 
 { 
     try 
     { 
         StringBuilder jsonString = new StringBuilder(); 
         jsonString.Append("{"); 
         PropertyInfo[] propertyInfo = jsonObject.GetType().GetProperties(); 
         for (int i = 0; i < propertyInfo.Length; i ) 
         { 
             object objectValue = propertyInfo[i].GetGetMethod().Invoke(jsonObject, null); 
             if (objectValue == null) 
             { 
                 continue; 
             } 
             StringBuilder value = new StringBuilder(); 
             if (objectValue is DateTime || objectValue is Guid || objectValue is TimeSpan) 
             { 
                 value.Append(""" objectValue.ToString() """); 
             } 
             else if (objectValue is string) 
             { 
                 value.Append(""" objectValue.ToString() """); 
             } 
             else if (objectValue is IEnumerable) 
             { 
                 value.Append(ToJson((IEnumerable)objectValue)); 
             } 
             else 
             { 
                 value.Append(""" objectValue.ToString() """); 
             } 
             jsonString.Append(""" propertyInfo[i].Name "":" value ","); ; 
         } 
         return jsonString.ToString().TrimEnd(',') "}"; 
     } 
     catch (Exception ex) 
     { 
         throw ex; 
     } 
 } 
 
 /// <summary>  
 /// 对象集合转换Json  
 /// </summary>  
 /// <param name="array">集合对象</param>  
 /// <returns>Json字符串</returns>  
 public static string ToJson(IEnumerable array) 
 { 
     string jsonString = "["; 
     foreach (object item in array) 
     { 
         jsonString = ToJson(item) ","; 
     } 
     jsonString.Remove(jsonString.Length - 1, jsonString.Length); 
     return jsonString "]"; 
 } 
 
 /// <summary>  
 /// 普通集合转换Json  
 /// </summary>  
 /// <param name="array">集合对象</param>  
 /// <returns>Json字符串</returns>  
 public static string ToArrayString(IEnumerable array) 
 { 
     string jsonString = "["; 
     foreach (object item in array) 
     { 
         jsonString = ToJson(item.ToString()) ","; 
     } 
     jsonString.Remove(jsonString.Length - 1, jsonString.Length); 
     return jsonString "]"; 
 } 
 
 /// <summary>  
 /// Datatable转换为Json  
 /// </summary>  
 /// <param name="table">Datatable对象</param>  
 /// <returns>Json字符串</returns>  
 public static string ToJson(DataTable dt) 
 { 
     StringBuilder jsonString = new StringBuilder(); 
     jsonString.Append("["); 
     DataRowCollection drc = dt.Rows; 
     for (int i = 0; i < drc.Count; i ) 
     { 
         jsonString.Append("{"); 
         for (int j = 0; j < dt.Columns.Count; j ) 
         { 
             string strKey = dt.Columns[j].ColumnName; 
             string strValue = drc[i][j].ToString(); 
             Type type = dt.Columns[j].DataType; 
             jsonString.Append(""" strKey "":"); 
             strValue = StringFormat(strValue, type); 
             if (j < dt.Columns.Count - 1) 
             { 
                 jsonString.Append(strValue ","); 
             } 
             else 
             { 
                 jsonString.Append(strValue); 
             } 
         } 
         jsonString.Append("},"); 
     } 
     jsonString.Remove(jsonString.Length - 1, 1); 
     jsonString.Append("]"); 
     return jsonString.ToString(); 
 } 
 
 /// <summary>  
 /// DataTable转成Json  
 /// </summary>  
 /// <param name="jsonName"></param>  
 /// <param name="dt"></param>  
 /// <returns></returns>  
 public static string ToJson(DataTable dt, string jsonName) 
 { 
     StringBuilder Json = new StringBuilder(); 
     if (string.IsNullOrEmpty(jsonName)) 
         jsonName = dt.TableName; 
     Json.Append("{"" jsonName "":["); 
     if (dt.Rows.Count > 0) 
     { 
         for (int i = 0; i < dt.Rows.Count; i ) 
         { 
             Json.Append("{"); 
             for (int j = 0; j < dt.Columns.Count; j ) 
             { 
                 Type type = dt.Rows[i][j].GetType(); 
                 Json.Append(""" dt.Columns[全球彩票注册平台,j].ColumnName.ToString() "":" StringFormat(dt.Rows[i][j].ToString(), type)); 
                 if (j < dt.Columns.Count - 1) 
                 { 
                     Json.Append(","); 
                 } 
             } 
             Json.Append("}"); 
             if (i < dt.Rows.Count - 1) 
             { 
                 Json.Append(","); 
             } 
         } 
     } 
     Json.Append("]}"); 
     return Json.ToString(); 
 } 
 
 /// <summary>  
 /// DataReader转换为Json  
 /// </summary>  
 /// <param name="dataReader">DataReader对象</param>  
 /// <returns>Json字符串</returns>  
 public static string ToJson(IDataReader dataReader) 
 { 
     StringBuilder jsonString = new StringBuilder(); 
     jsonString.Append("["); 
 
     while (dataReader.Read()) 
     { 
         jsonString.Append("{"); 
         for (int i = 0; i < dataReader.FieldCount; i ) 
         { 
             Type type = dataReader.GetFieldType(i); 
             string strKey = dataReader.GetName(i); 
             string strValue = dataReader[i].ToString(); 
             jsonString.Append(""" strKey "":"); 
             strValue = StringFormat(strValue, type); 
             if (i < dataReader.FieldCount - 1) 
             { 
                 jsonString.Append(strValue ","); 
             } 
             else 
             { 
                 jsonString.Append(strValue); 
             } 
         } 
         jsonString.Append("},"); 
     } 
     dataReader.Close(); 
     jsonString.Remove(jsonString.Length - 1, 1); 
     jsonString.Append("]"); 
     if (jsonString.Length == 1) 
     { 
         return "[]"; 
     } 
     return jsonString.ToString(); 
 } 
 
 /// <summary>  
 /// DataSet转换为Json  
 /// </summary>  
 /// <param name="dataSet">DataSet对象</param>  
 /// <returns>Json字符串</returns>  
 public static string ToJson(DataSet dataSet) 
 { 
     string jsonString = "{"; 
     foreach (DataTable table in dataSet.Tables) 
     { 
         jsonString = """ table.TableName "":" ToJson(table)

C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。

First of all, we have to fetch the records from the database (MS Sqlserver) into the C# DataTable, or we can add dynamic rows to our DataTable. So our code looks like as written below.

First of all, we have to fetch the records from the database (MS Sqlserver) into the C# DataTable, or we can add dynamic rows to our DataTable. So our code looks like as written below.

  • ","; 
         } 
         jsonString = jsonString.TrimEnd(','); 
         return jsonString "}"; 
     } 
     
     /// <summary>  
     /// 过滤特殊字符  
     /// </summary>  
     /// <param name="s"></param>  
     /// <returns></returns>  
     private static string String2Json(String s) 
     { 
         StringBuilder sb = new StringBuilder(); 
         for (int i = 0; i < s.Length; i ) 
         { 
             char c = s.ToCharArray()[i]; 
             switch (c) 
             { 
                 case '"': 
                     sb.Append("\""); break; 
                 case '\': 
                     sb.Append("\\"); break; 
                 case '/': 
                     sb.Append("\/"); break; 
                 case 'b': 
                     sb.Append("\b"); break; 
                 case 'f': 
                     sb.Append("\f"); break; 
                 case 'n': 
                     sb.Append("\n"); break; 
                 case 'r': 
                     sb.Append("\r"); break; 
                 case 't': 
                     sb.Append("\t"); break; 
                 default: 
                     sb.Append(c); break; 
             } 
         } 
         return sb.ToString(); 
     } 
     
     /// <summary>  
     /// 格式化字符型、日期型、布尔型  
     /// </summary>  
     /// <param name="str"></param>  
     /// <param name="type"></param>  
     /// <returns></returns>  
     private static string StringFormat(string str, Type type) 
     { 
         if (type != typeof(string) && string.IsNullOrEmpty(str)) 
         { 
             str = """ str """; 
         } 
         else if (type == typeof(string)) 
         { 
             str = String2Json(str); 
             str = """ str """; 
         } 
         else if (type == typeof(DateTime)) 
         { 
             str = """ str.Split(' ')[0] """; 
         } 
         else if (type == typeof(bool)) 
         { 
             str = str.ToLower(); 
         } 
     
         return str; 
     } 

public class ConvertJson
    {
        #region 私有方法
        /// <summary>
        /// 过滤特殊字符
        /// </summary>
        /// <param name="s">字符串</param>
        /// <returns>json字符串</returns>
        private static string String2Json(String s)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.Length; i )
            {
                char c = s.ToCharArray()[i];
                switch (c)
                {
                    case '"':
                        sb.Append("\""); break;
                    case '\':
                        sb.Append("\\"); break;
                    case '/':
                        sb.Append("\/"); break;
                    case 'b':
                        sb.Append("\b"); break;
                    case 'f':
                        sb.Append("\f"); break;
                    case 'n':
                        sb.Append("\n"); break;
                    case 'r':
                        sb.Append("\r"); break;
                    case 't':
                        sb.Append("\t"); break;
                    default:
                        sb.Append(c); break;
                }
            }
            return sb.ToString();
        }
        /// <summary>
        /// 格式化字符型、日期型、布尔型
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private static string StringFormat(string str, Type type)
        {
            if (type == typeof(string))
            {
                str = String2Json(str);
                str = """   str   """;
            }
            else if (type == typeof(DateTime))
            {
                str = """   str   """;
            }
            else if (type == typeof(bool))
            {
                str = str.ToLower();
            }
            else if (type != typeof(string) && string.IsNullOrEmpty(str))
            {
                str = """   str   """;
            }
            return str;
        }

//*

//*

   /// <summary>
    /// List转成json
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="jsonName"></param>
    /// <param name="list"></param>
    /// <returns></returns>
    public static string ListToJson<T>(IList<T> list, string jsonName)
    {
        StringBuilder Json = new StringBuilder();
        if (string.IsNullOrEmpty(jsonName))
            jsonName = list[0].GetType().Name;
        Json.Append("{"" jsonName "":[");
        if (list.Count > 0)
        {
            for (int i = 0; i < list.Count; i )
            {
                T obj = Activator.CreateInstance<T>();
                PropertyInfo[] pi = obj.GetType().GetProperties();
                Json.Append("{");
                for (int j = 0; j < pi.Length; j )
                {
                    Type type = pi[j].GetValue(list[i], null).GetType();
                    Json.Append(""" pi[j].Name.ToString() "":"

        #endregion

public DataTable getData()

public DataTable getData()

  • StringFormat(pi[j].GetValue(list[i], null).ToString(), type));
     
                        if (j < pi.Length - 1)
                        {
                            Json.Append(",");
                        }
                    }
                    Json.Append("}");
                    if (i < list.Count - 1)
                    {
                        Json.Append(",");
                    }
                }
            }
            Json.Append("]}");
            return Json.ToString();
        }
     
        /// <summary>
        /// List转成json
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static string ListToJson<T>(IList<T> list)
        {
            object obj = list[0];
            return ListToJson<T>(list, obj.GetType().Name);
        }
     
        /// <summary>
        /// 对象转换为Json字符串
        /// </summary>
        /// <param name="jsonObject">对象</param>
        /// <returns>Json字符串</returns>
        public static string ToJson(object jsonObject)
        {
            try
            {
                StringBuilder jsonString = new StringBuilder();
                jsonString.Append("{");
                PropertyInfo[] propertyInfo = jsonObject.GetType().GetProperties();
                for (int i = 0; i < propertyInfo.Length; i )
                {
                    object objectValue = propertyInfo[i].GetGetMethod().Invoke(jsonObject, null);
                    if (objectValue == null)
                    {
                        continue;
                    }
                    StringBuilder value = new StringBuilder();
                    if (objectValue is DateTime || objectValue is Guid || objectValue is TimeSpan)
                    {
                        value.Append(""" objectValue.ToString() """);
                    }
                    else if (objectValue is string)
                    {
                        value.Append(""" objectValue.ToString() """);
                    }
                    else if (objectValue is IEnumerable)
                    {
                        value.Append(ToJson((IEnumerable)objectValue));
                    }
                    else
                    {
                        value.Append(""" objectValue.ToString() """);
                    }
                    jsonString.Append(""" propertyInfo[i].Name "":" value ","); ;
                }
                return jsonString.ToString().TrimEnd(',') "}";
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
     
        /// <summary>
        /// 对象集合转换Json
        /// </summary>
        /// <param name="array">集合对象</param>
        /// <returns>Json字符串</returns>
        public static string ToJson(IEnumerable array)
        {
            string jsonString = "[";
            foreach (object item in array)
            {
                jsonString = ToJson(item) ",";
            }
            jsonString.Remove(jsonString.Length - 1, jsonString.Length);
            return jsonString "]";
        }
     
        /// <summary>
        /// 普通集合转换Json
        /// </summary>
        /// <param name="array">集合对象</param>
        /// <returns>Json字符串</returns>
        public static string ToArrayString(IEnumerable array)
        {
            string jsonString = "[";
            foreach (object item in array)
            {
                jsonString = ToJson(item.ToString()) ",";
            }
            jsonString.Remove(jsonString.Length - 1, jsonString.Length);
            return jsonString "]";
        }
     
        /// <summary>
        /// Datatable转换为Json
        /// </summary>
        /// <param name="table">Datatable对象</param>
        /// <returns>Json字符串</returns>
        public static string ToJson(DataTable dt)
        {
            StringBuilder jsonString = new StringBuilder();
            jsonString.Append("[");
            DataRowCollection drc = dt.Rows;
            for (int i = 0; i < drc.Count; i )
            {
                jsonString.Append("{");
                for (int j = 0; j < dt.Columns.Count; j )
                {
                    string strKey = dt.Columns[j].ColumnName;
                    string strValue = drc[i][j].ToString();
                    Type type = dt.Columns[j].DataType;
                    jsonString.Append(""" strKey "":");
                    strValue = StringFormat(strValue, type);
                    if (j < dt.Columns.Count - 1)
                    {
                        jsonString.Append(strValue ",");
                    }
                    else
                    {
                        jsonString.Append(strValue);
                    }
                }
                jsonString.Append("},");
            }
            jsonString.Remove(jsonString.Length - 1, 1);
            jsonString.Append("]");
            return jsonString.ToString();
        }
     
        /// <summary>
        /// DataTable转成Json
        /// </summary>
        /// <param name="jsonName"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string ToJson(DataTable dt, string jsonName)
        {
            StringBuilder Json = new StringBuilder();
            if (string.IsNullOrEmpty(jsonName))
                jsonName = dt.TableName;
            Json.Append("{"" jsonName "":[");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i )
                {
                    Json.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j )
                    {
                        Type type = dt.Rows[i][j].GetType();
                        Json.Append(""" dt.Columns[j].ColumnName.ToString() "":" StringFormat(dt.Rows[i][j].ToString(), type));
                        if (j < dt.Columns.Count - 1)
                        {
                            Json.Append(",");
                        }
                    }
                    Json.Append("}");
                    if (i < dt.Rows.Count - 1)
                    {
                        Json.Append(",");
                    }
                }
            }
            Json.Append("]}");
            return Json.ToString();
        }
     
        /// <summary>
        /// DataReader转换为Json
        /// </summary>
        /// <param name="dataReader">DataReader对象</param>
        /// <returns>Json字符串</returns>
        public static string ToJson(IDataReader dataReader)
        {
            StringBuilder jsonString = new StringBuilder();
            jsonString.Append("[");
     
            while (dataReader.Read())
            {
                jsonString.Append("{");
                for (int i = 0; i < dataReader.FieldCount; i )
                {
                    Type type = dataReader.GetFieldType(i);
                    string strKey = dataReader.GetName(i);
                    string strValue = dataReader[i].ToString();
                    jsonString.Append(""" strKey "":");
                    strValue = StringFormat(strValue, type);
                    if (i < dataReader.FieldCount - 1)
                    {
                        jsonString.Append(strValue ",");
                    }
                    else
                    {
                        jsonString.Append(strValue);
                    }
                }
                jsonString.Append("},");
            }
            dataReader.Close();
            jsonString.Remove(jsonString.Length - 1, 1);
            jsonString.Append("]");
            if (jsonString.Length == 1)
            {
                return "[]";
            }
            return jsonString.ToString();
        }
     
        /// <summary>
        /// DataSet转换为Json
        /// </summary>
        /// <param name="dataSet">DataSet对象</param>
        /// <returns>Json字符串</returns>
        public static string ToJson(DataSet dataSet)
        {
            string jsonString = "{";
            foreach (DataTable table in dataSet.Tables)
            {
                jsonString = """ table.TableName "":" ToJson(table) ",";
            }
            jsonString = jsonString.TrimEnd(',');
            return jsonString "}";
        }
     
        /// <summary>
        /// 过滤特殊字符
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private static string String2Json(String s)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.Length; i )
            {
                char c = s.ToCharArray()[i];
                switch (c)
                {
                    case '"':
                        sb.Append("\""); break;
                    case '\':
                        sb.Append("\\"); break;
                    case '/':
                        sb.Append("\/"); break;
                    case 'b':
                        sb.Append("\b"); break;
                    case 'f':
                        sb.Append("\f"); break;
                    case 'n':
                        sb.Append("\n"); break;
                    case 'r':
                        sb.Append("\r"); break;
                    case 't':
                        sb.Append("\t"); break;
                    default:
                        sb.Append(c); break;
                }
            }
            return sb.ToString();
        }
     
        /// <summary>
        /// 格式化字符型、日期型、布尔型
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private static string StringFormat(string str, Type type)
        {
            if (type != typeof(string) && string.IsNullOrEmpty(str))
            {
                str = """ str """;
            }
            else if (type == typeof(string))
            {
                str = String2Json(str);
                str = """ str """;
            }
            else if (type == typeof(DateTime))
            {
                str = """ str.Split(' ')[0] """;
            }
            else if (type == typeof(bool))
            {
                str = str.ToLower();
            }
     
            return str;
        }

        #region list转换成JSON
        /// <summary>
        /// list转换为Json
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static string ListToJson<T>(IList<T> list)
        {
            object obj = list[0];
            return ListToJson<T>(list, obj.GetType().Name);
        }
        /// <summary>
        /// list转换为json
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="list"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        private static string ListToJson<T>(IList<T> list, string JsonName)
        {
            StringBuilder Json = new StringBuilder();
            if (string.IsNullOrEmpty(JsonName))
                JsonName = list[0].GetType().Name;
            Json.Append("{""   JsonName   "":[");
            if (list.Count > 0)
            {
                for (int i = 0; i < list.Count; i )
                {
                    T obj = Activator.CreateInstance<T>();
                    PropertyInfo[] pi = obj.GetType().GetProperties();
                    Json.Append("{");
                    for (int j = 0; j < pi.Length; j )
                    {
                        Type type = pi[j].GetValue(list[i], null).GetType();
                        Json.Append("""   pi[j].Name.ToString()   "":"   StringFormat(pi[j].GetValue(list[i], null).ToString(), type));
                        if (j < pi.Length - 1)
                        {
                            Json.Append(",");
                        }
                    }
                    Json.Append("}");
                    if (i < list.Count - 1)
                    {
                        Json.Append(",");
                    }
                }
            }
            Json.Append("]}");
            return Json.ToString();
        }
        #endregion

{

{

 

        #region 对象转换为Json
        /// <summary>
        /// 对象转换为json
        /// </summary>
        /// <param name="jsonObject">json对象</param>
        /// <returns>json字符串</returns>
        public static string ToJson(object jsonObject)
        {
            string jsonString = "{";
            PropertyInfo[] propertyInfo = jsonObject.GetType().GetProperties();
            for (int i = 0; i < propertyInfo.Length; i )
            {
                object objectValue = propertyInfo[i].GetGetMethod().Invoke(jsonObject, null);
                string value = string.Empty;
                if (objectValue is DateTime || objectValue is Guid || objectValue is TimeSpan)
                {
                    value = "'"   objectValue.ToString()   "'";
                }
                else if (objectValue is string)
                {
                    value = "'"   ToJson(objectValue.ToString())   "'";
                }
                else if (objectValue is IEnumerable)
                {
                    value = ToJson((IEnumerable)objectValue);
                }
                else
                {
                    value = ToJson(objectValue.ToString());
                }
                jsonString  = """   ToJson(propertyInfo[i].Name)   "":"   value   ",";
            }
            jsonString.Remove(jsonString.Length - 1, jsonString.Length);
            return jsonString   "}";
        }

DataTable dt = new DataTable();

DataTable dt = new DataTable();

summary /// List转成json /// /summary /// typeparam name=T/typeparam /// param name=jsonName/param /// param name=list/param /// returns/returns public static string Li...

        #endregion

dt.Columns.Add("UserId", typeof(Int32));

dt.Columns.Add("UserId", typeof(Int32));

        #region 对象集合转换为json
        /// <summary>
        /// 对象集合转换为json
        /// </summary>
        /// <param name="array">对象集合</param>
        /// <returns>json字符串</returns>
        public static string ToJson(IEnumerable array)
        {
            string jsonString = "{";
            foreach (object item in array)
            {
                jsonString  = ToJson(item)   ",";
            }
            jsonString.Remove(jsonString.Length - 1, jsonString.Length);
            return jsonString   "]";
        }
        #endregion

dt.Columns.Add("UserName", typeof(string));

dt.Columns.Add("UserName", typeof(string));

        #region 普通集合转换Json
        /// <summary>    
        /// 普通集合转换Json   
        /// </summary>   
        /// <param name="array">集合对象</param> 
        /// <returns>Json字符串</returns>  
        public static string ToArrayString(IEnumerable array)
        {
            string jsonString = "[";
            foreach (object item in array)
            {
                jsonString = ToJson(item.ToString())   ",";
            }
            jsonString.Remove(jsonString.Length - 1, jsonString.Length);
            return jsonString   "]";
        }
        #endregion

dt.Columns.Add("Education", typeof(string));

dt.Columns.Add("Education", typeof(string));

        #region  DataSet转换为Json
        /// <summary>    
        /// DataSet转换为Json   
        /// </summary>    
        /// <param name="dataSet">DataSet对象</param>   
        /// <returns>Json字符串</returns>    
        public static string ToJson(DataSet dataSet)
        {
            string jsonString = "{";
            foreach (DataTable table in dataSet.Tables)
            {
                jsonString  = """   table.TableName   "":"   ToJson(table)   ",";
            }
            jsonString = jsonString.TrimEnd(',');
            return jsonString   "}";
        }
        #endregion

dt.Columns.Add("Location", typeof(string));

dt.Columns.Add("Location", typeof(string));

本文由全球彩票平台发布于全球彩票注册平台编程,转载请注明出处:【全球彩票注册平台】MVC项目开发之统计图echa

TAG标签: 全球彩票平台
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。