数据页面代码
View Code
#region 将table转换为json
/// <summary>
/// 将table转换为json
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public string ConvertDataTableToJson(DataTable dt)
{
StringBuilder sbs = new StringBuilder();
if (dt.Rows.Count > 0)
{
sbs.Append("{'" + dt.TableName + "':[");
string str = "";
foreach (DataRow dr in dt.Rows)
{
//获取列名
string result = "";
foreach (DataColumn dc in dt.Columns)
{
result += string.Format(",'{0}':'{1}'", dc.ColumnName, dr[dc.ColumnName]);
}
result = result.Substring(1);
result = ",{" + result + "}";
str += result;
}
str = str.Substring(1);
sbs.Append(str);
sbs.Append("]}");
return sbs.ToString();
}
else
{
return "";
}
}
#endregion
js处理
View Code
var objs = xmlHttp.responseText;
objs = eval("(" + objs + ")");
objs = objs.UserInfo;
//UserInfo 表名
var name=objs.name; //name是字段