在EasyUI http://www.jeasyui.com/demo/main/get_users.php 响应数据如下格式:
{ "total": "11", "rows": [ { "id": "50528", "firstname": "wrerw", "lastname": "erwerw", "phone": "", "email": "" }, { "id": "50529", "firstname": "asdf", "lastname": "asdf", "phone": "", "email": "asdf@asdf.c" }, { "id": "50532", "firstname": "sdfdsfds", "lastname": "fsdfdsfagcdga", "phone": "", "email": "" }, { "id": "50533", "firstname": "ewfg", "lastname": "gdfgdfgdfg", "phone": "", "email": "" }, { "id": "50534", "firstname": "sagfg", "lastname": "wwGSGSG", "phone": "", "email": "" }, { "id": "50535", "firstname": "sa", "lastname": "sa", "phone": "sa", "email": "sa@dssddsd.dsd" }, { "id": "50536", "firstname": "asdf", "lastname": "asdf", "phone": "asdf", "email": "asdf@asdf.com" }, { "id": "50537", "firstname": "s", "lastname": "sdf", "phone": "", "email": "" }, { "id": "50538", "firstname": "33", "lastname": "sd", "phone": "13445", "email": "131@131.com" }, { "id": "50539", "firstname": "1", "lastname": "1", "phone": "1", "email": "1@qq.com" } ] }
//C#后台动态拼接
DataTable dt = new DataTable(); StringBuilder str = new StringBuilder(); str.Append("{"total":"" + dt.Rows.Count + "","rows":["); for (int i = 0; i < dt.Rows.Count; i++) { //就是这些 转义很容易造成错误 str.Append("{"FtyVendorCode":"" + dt.Rows[i]["CustID"].ToString() + "","CompanyName":"" + dt.Rows[i]["CompanyName"].ToString() + "","Contact":"" + dt.Rows[i]["ContactPerson"].ToString() + "","EMail":"" + dt.Rows[i]["ContactEmail"].ToString() + "","Phone":"" + dt.Rows[i]["ContactPhone"].ToString() + """); } str.ToString().TrimEnd(new char[] { ',' }); str.Append("]}"); context.Response.Write(str.ToString());