public void order_v_list(HttpContext context)
{
LayJsonModel msgmodel = new LayJsonModel();
try
{
string message = string.Empty;
string id = context.Request["id"];
string sqlstr = "select docentry,taxdate from orders where cardname='泉州一范'";
DataTable dt = bdc.GetDataTable(sqlstr);
StringBuilder JsonSb = new StringBuilder();
if (dt != null && dt.Rows.Count > 0)
{
string jsonString = JsonConvert.SerializeObject(dt);
msgmodel.code = "0";
msgmodel.count = 5000;
msgmodel.msg = "";
// JsonSb.Append("[");
List<dataModel> dmodel = new List<dataModel>();
for (int i = 0; i < dt.Rows.Count; i++)
{
//dataModel dmodels = new dataModel();
//dmodels.DocEntry = dt.Rows[i]["DocEntry"].ToString();
//dmodels.taxDate = dt.Rows[i]["taxDate"].ToString();
//msgmodel.data.Add(dmodels);//这样写会提示未将对象引用到实例
dataModel d = new dataModel();
d.DocEntry = dt.Rows[i]["DocEntry"].ToString();
d.taxDate = dt.Rows[i]["taxDate"].ToString();
dmodel.Add(d);
}
msgmodel.data = dmodel;
//string tmp = JsonSb.ToString().Trim(',') + "]";
//msgmodel.data = tmp;
}
string JSONObj = JsonConvert.SerializeObject(msgmodel);
context.Response.ContentType = "text/plain";
context.Response.Write(JSONObj); //返回给前台页面
}
catch (Exception ex)
{
context.Response.ContentType = "text/plain";
context.Response.Write(ex.Message); //返回给前台页面
context.Response.End();
}
}