Asp.net mvc 需要锯齿状数组的帮助,将IQueryable结果放入数组

Asp.net mvc 需要锯齿状数组的帮助,将IQueryable结果放入数组,asp.net-mvc,Asp.net Mvc,是否有人知道如何将当前在qry IQueryable对象中的结果转换为锯齿状数组,格式如下: series: [{ name: '2', data: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] }, { name: '3', data: [1, 0, 0, 0

是否有人知道如何将当前在qry IQueryable对象中的结果转换为锯齿状数组,格式如下:

        series:
             [{
                name: '2',
                data: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
                    }, {
                name: '3',
                data: [1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 3, 0]

                }]
我的问题是,目前我的代码在12个元素的数据部分用双引号括起来,也就是说,在客户端的调试器中看起来是这样的:

?结果[0] {...} [0]: "2" [1]: "[0,0,0,0,0,0,1,0,0,0,0,0]" ?结果[1] {...} [0]: "3" [1] :“[1,0,0,0,0,0,0,0,0,0,0,0,0]”

问题是我的数组包含一个字符串元素,而不是12个数字的数组

这是我的控制器代码,目前它将12个数字部分作为一个大字符串返回:

        var qry = from i in _db.Complaints
             where i.Site.SiteDescription.Contains(searchTextSite)
                  && (i.Raised >= startDate && i.Raised <= endDate)
            group i by i.ComplaintNatureTypeId.ToString()
            into grp select new 
            {
                Type = grp.Key,
                Count = "[" + grp.Where(c => c.Raised.Month == 1).Count() + "," + 
                        grp.Where(c => c.Raised.Month == 2).Count() + "," +
                        grp.Where(c => c.Raised.Month == 3).Count() + "," + 
                        grp.Where(c => c.Raised.Month == 4).Count() + "," +
                        grp.Where(c => c.Raised.Month == 5).Count() + "," + 
                        grp.Where(c => c.Raised.Month == 6).Count() + "," +
                        grp.Where(c => c.Raised.Month == 7).Count() + "," + 
                        grp.Where(c => c.Raised.Month == 8).Count() + "," +
                        grp.Where(c => c.Raised.Month == 9).Count() + "," + 
                        grp.Where(c => c.Raised.Month == 10).Count() + "," +
                        grp.Where(c => c.Raised.Month == 11).Count() + "," + 
                        grp.Where(c => c.Raised.Month == 12).Count() + "]"

            };


        return Json(qry.ToArray(), JsonRequestBehavior.AllowGet);
var qry=来自i in _db
其中i.Site.SiteDescription.Contains(searchTextSite)
&&(i.Raised>=startDate&i.Raised c.Raised.Month==1.Count()+,“+
grp.Where(c=>c.Raised.Month==2.Count()+“,”+
grp.Where(c=>c.Raised.Month==3.Count()+“,”+
grp.Where(c=>c.Raised.Month==4.Count()+“,”+
grp.Where(c=>c.Raised.Month==5.Count()+“,”+
grp.Where(c=>c.Raised.Month==6.Count()+“,”+
grp.Where(c=>c.Raised.Month==7.Count()+“,”+
grp.Where(c=>c.Raised.Month==8.Count()+“,”+
grp.Where(c=>c.Raised.Month==9.Count()+“,”+
grp.Where(c=>c.Raised.Month==10.Count()+“,”+
grp.Where(c=>c.Raised.Month==11.Count()+“,”+
grp.Where(c=>c.Raised.Month==12.Count()+“]”
};
返回Json(qry.ToArray(),JsonRequestBehavior.AllowGet);

您正在将count属性创建为字符串,如果它不是数组:

Count = new [] {
grp.Where(c => c.Raised.Month == 1).Count(),
grp.Where(c => c.Raised.Month == 2).Count(),
...
grp.Where(c => c.Raised.Month == 12).Count()
}

您需要传递一个对象,
Json
将把它序列化为Json字符串

Count = new int[] {
   grp.Where(c => c.Raised.Month == 1).Count(),
   grp.Where(c => c.Raised.Month == 2).Count(),
   grp.Where(c => c.Raised.Month == 3).Count(),
   grp.Where(c => c.Raised.Month == 4).Count(),
   grp.Where(c => c.Raised.Month == 5).Count(), 
   grp.Where(c => c.Raised.Month == 6).Count(),
   grp.Where(c => c.Raised.Month == 7).Count(), 
   grp.Where(c => c.Raised.Month == 8).Count(),
   grp.Where(c => c.Raised.Month == 9).Count(), 
   grp.Where(c => c.Raised.Month == 10).Count(),
   grp.Where(c => c.Raised.Month == 11).Count(), 
   grp.Where(c => c.Raised.Month == 12).Count()
}
或者你可以这样做:

Count = Enumerable.Range(1, 12).Select(x => grp.Where(c => c.Raised.Month == x).Count())

我想我需要创建一个数组并循环qry对象,但问题是12个数字的数组是一个字符串。与此相关的任何人都建议一种方法,非常感谢