• 未定义对象


    public partial class LayJsonModel
        {
            /// <summary>
            /// 状态
            /// </summary>
            public string code
            {
                get;
                set;
            }
            /// <summary>
            /// 消息
            /// </summary>
            public string msg
            {
                get;
                set;
            }
            public int count
            {
                get;
                set;
            }
            /// <summary>
            /// 数据
            /// </summary>
            public List<dataModel> data
            {
                get;
                set;
            }
     
        }
    View C
      public class dataModel
        {
            public string DocEntry
            {get;
            set;}
            public string taxDate
            {
                get;
                set;
            }
        }
    View Code
    ode
    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();
            }
        }
    View Code
  • 相关阅读:
    程序员修炼之道阅读笔记1
    构建之法阅读笔记6
    构建之法阅读笔记5
    构建之法阅读笔记4
    构建之法阅读笔记3
    构建之法阅读笔记2
    关于搜狗输入法的评价
    找水王
    用户场景
    个人工作总结
  • 原文地址:https://www.cnblogs.com/niyl/p/9515984.html
Copyright © 2020-2023  润新知