asp.net DataSet转换成josn并输出
程序员文章站
2022-05-01 17:36:55
public class JsonUtil
{
public string ToJson(DataSet dataSet)
{...
public class JsonUtil { public string ToJson(DataSet dataSet) { string jsonString = "{"; foreach (DataTable table in dataSet.Tables) { jsonString += """" + table.TableName + """:" + ToJson(table) + ","; } jsonString = jsonString.TrimEnd(','); return jsonString + "}"; } public string ToJson(DataTable dt) { StringBuilder jsonString = new StringBuilder(); jsonString.Append("["); DataRowCollection drc = dt.Rows; for (int i = 0; i
使用
JsonUtil ju = new JsonUtil(); Response.Write(ju.ToJson(ds));如果解析有问题可以把代码中的""""用"\""替换