将JSON数据转换为HTML表 [英] Convert JSON data to HTML table
问题描述
大家好,我希望一切顺利!
最初在c#方法中我从sql查询中获取数据如下
UserNumber 2015-01-01 2015-01-02 2015-01-03 ....
emp001上午10点11点6点〜
emp002 11am 10p 7pm ....
然后我使用下面的代码序列化这些数据
Hi Guys i hope all are doing well!
Initially in c# method i am getting data from sql query like below
UserNumber 2015-01-01 2015-01-02 2015-01-03 ....
emp001 10am 11am 6pm ....
emp002 11am 10p 7pm ....
Then i am serializing this data using below code
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
然后我将这些数据返回给json并且我在那里捕获,使用下面的代码
Then after i am returning this data to json and i am capturing there, using below code
$.ajax({
type: "POST",
url: "Default.aspx/GetData",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(obj),
success: function (response) {
var tabledata = response.d;
},
failure: function (response) {
alert(response.d);
}
});
现在我想将这些数据插入到html表 中,但这里的重要事项是列名称每次都会更改,具体取决于用户选择的日期 。那怎么能解决这个问题呢。
请提前帮助我,谢谢。
Now i want to insert this data into html table but here the big deal is the column names will change every time depends on user selected dates. SO how can i solve this.
Please help me and thanks in advance.
推荐答案
.ajax({
类型: POST,
url: Default.aspx / GetData,
contentType: application / json; charset = utf-8,
dataType: json,
数据: JSON .stringify(obj),
成功: function (响应){
var tabledata = response.d;
},
失败: function (响应){
alert(response.d);
}
});
.ajax({ type: "POST", url: "Default.aspx/GetData", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify(obj), success: function (response) { var tabledata = response.d; }, failure: function (response) { alert(response.d); } });
现在我想将这些数据插入到html表 中,但这里的重要事项是列名称每次都会更改,具体取决于用户选择的日期 。那怎么能解决这个问题。
请帮助我,并提前致谢。
Now i want to insert this data into html table but here the big deal is the column names will change every time depends on user selected dates. SO how can i solve this.
Please help me and thanks in advance.
看看这个链接
http://www.dotnetpickles.com/2014/04/json- to-html-table.html [ ^ ]
希望这会有所帮助
check out this link
http://www.dotnetpickles.com/2014/04/json-to-html-table.html[^]
hope this would help
最后我解决了我的问题。这里的代码是
Finally i solved my stuff. Here the code is
这篇关于将JSON数据转换为HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!