标签:
创建model类,声明所需要的字段
public class model { public model() { Id = string.Empty; name = string.Empty; time = string.Empty; Status = string.Empty; } public string Id { get; set; } public string name { get; set; } public string time { get; set; } public string Status { get; set; } }
页面输出
string str = ""; string sql = "select time,name,id from name order by time desc"; DataTable dt = new DB.DB().RunSqlGetDataTable(sql); List<model> list = new List<model>(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { model m = new model(); m.Id = dt.Rows[i]["id"].ToString(); m.name = dt.Rows[i]["name"].ToString(); m.time = dt.Rows[i]["time"].ToString(); list.Add(m); } } str = JsonConvert.SerializeObject(list); context.Response.Write(str);
命名空间引用
using System.Data;
using Newtonsoft.Json;
页面输出效果
标签:
原文地址:http://www.cnblogs.com/jingyong001/p/5531922.html