如何在后台获取ashx的值
1个回答
展开全部
/// <summary>
/// 将dt转化成Json数据
/// </summary>
/// <param name="dt"></param>
/// <param name="fromIndex">起始编号</param>
/// <param name="totalCountName">总行数返回名</param>
/// <param name="tbname">数组名</param>
/// <returns></returns>
public static string DT(DataTable dt, int fromIndex, string totalCountName = "recordcount", string tbname = "table")
{
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("\"" + totalCountName + "\":" + dt.Rows.Count + ",\"" + tbname + "\": [");
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i > 0)
{
jsonBuilder.Append(",");
}
jsonBuilder.Append("{");
jsonBuilder.Append("\"no\":" + (fromIndex + i + 1) + ",");
for (int j = 0; j < dt.Columns.Count; j++)
{
if (j > 0)
{
jsonBuilder.Append(",");
}
jsonBuilder.Append("\"" + dt.Columns[j].ColumnName.ToLower() + "\":\"" + dt.Rows[i][j].ToString() + "\"");
}
jsonBuilder.Append("}");
}
jsonBuilder.Append("]");
return jsonBuilder.ToString();
}
获取到字段列名,然后读取出对应行列的数据即可了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询