ApiController 实现DataTable转json并返
2018-07-26 本文已影响0人
蚁丶点
// GET api//5
public HttpResponseMessage Get(int id)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Dept");
DataRow dr = dt.NewRow();
dr["ID"] = "32";
dr["Dept"] = "專案開發技術部";
dt.Rows.Add(dr);
string strJson = JsonConvert.SerializeObject(dt);
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(strJson, Encoding.GetEncoding("UTF-8"), "application/json") };
return result;
}