本帖最后由 kzc_ljl 于 2011-04-12 23:46:27 编辑

解决方案 »

  1.   

    序列化或者自己用stringBuilder 拼接 json
      

  2.   

    我现在是这样写的
    public JsonResult GetTableA()
            {
                List<TableA> lst;
                using (HBJYModels e = new HBJYModels())
                {
                    lstUsg = (from t in e.TableA
                              select t).ToList<TableA>();
                }            return Json(lst, JsonRequestBehavior.AllowGet);
            }
    我希望能同时返回 TableA 和 TableB
      

  3.   

        public class TableA
        {
            public TableA(int id, string name)
            {
                this.iD = id;
                this.name = name;
            }
            private int iD;        public int ID
            {
                get { return iD; }
                set { iD = value; }
            }
            private string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }
        public class TableB
        {
            public TableB(int id, string name)
            {
                this.iD = id;
                this.name = name;
            }
            private int iD;        public int ID
            {
                get { return iD; }
                set { iD = value; }
            }
            private string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }
            IList<TableA> ilistA = new List<TableA>();
            ilistA.Add(new TableA(1, "a"));
            ilistA.Add(new TableA(2, "b"));
            IList<TableB> ilistB = new List<TableB>();
            ilistB.Add(new TableB(3, "c"));
            ilistB.Add(new TableB(4, "d"));
            var linq = (from a in ilistA select new { ID = a.ID, Name = a.Name }).Union(from b in ilistB select new { ID = b.ID, Name = b.Name });
            JavaScriptSerializer json = new JavaScriptSerializer();
            Response.Write(json.Serialize(linq));
    /*
    结果:
    [{"ID":1,"Name":"a"},{"ID":2,"Name":"b"},{"ID":3,"Name":"c"},{"ID":4,"Name":"d"}] 
    */
      

  4.   

    谁有asp.net mvc一个功能模块 发我邮箱[email protected]
      

  5.   

    json格式日期处理
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="tao145">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <script language="javascript">
     function JsonDateFormat(jsondate) {   
       /*
                 \/Date(1291232956278+0800)\/
       */
       var reg=/\/Date\((\d+)\+\d+\)\//i;
       arr=reg.exec(jsondate);
       var milliSeconds= arr[1];
       var date=new Date(parseInt(milliSeconds));
       var month=date.getMonth()+1;
       var year=date.getFullYear();
       return year+"-"+month+"-"+date.getDate();
     }
      </script>
      
     </head> <body onload="document.getElementById('myDiv').innerText=JsonDateFormat('\/Date(1291232956278+0800)\/')">
    <div id="myDiv" style="border:1px black solid;width:500px;height:100px;">
    </div>
     </body>
    </html>
      

  6.   

    查询两个实体类的话而要用list返回 得自己重新建一个实体类封装两个实体类所要用的字段。用JavaScriptSerializer 序列化就行
      

  7.   

                var date = new Date(parseInt(json[0].Time.replace("/Date(","").replace(")/","").split('+')[0]));
                var y = date.getFullYear();
                var m = date.getMonth()+1;
                var d = date.getDate();
                var h = date.getHours();
                var m = date.getMinutes();
                var s = date.getSeconds();
                alert(y+"-"+m+"-"+d+" "+h+":"+m+":"+s);//或者直接处理完后在传过来
            var linq = (from a in ilistA select new { ID = a.ID, Name = a.Name, Time = a.Time.ToString("yyyy-MM-dd HH:mm:ss") }).Union(from b in ilistB select new { ID = b.ID, Name = b.Name, Time = b.Time.ToString("yyyy-MM-dd HH:mm:ss") });