将项附加到JsonResult数据

时间:2014-01-23 17:32:57

标签: c# json jsonresult

我有一个像下面这样的JsonResult:

new JsonResult()
            {
                Data = new
                {
                    item01 = "this is the first item",
                    item02 = "this is the second item",
                    item03 = "this is the third item"
                }
            };

所以我想要的是将其他项目(假设item04和item05)添加到Data中,这样新的JsonResult将是:

new JsonResult()
            {
                Data = new
                {
                    item01 = "this is the first item",
                    item02 = "this is the second item",
                    item03 = "this is the third item",
                    item04 = "this is the fourth item",
                    item05 = "this is the fifth item"
                }
            };

如何将item04和item05添加到JsonResult数据中以获得上面显示的结果jsut?

或者更好的是,我如何将item01,item02,item03分组到一个组中,将item04和item05分组到另一个组中以获得以下数据结构?

JsonResult r = new JsonResult() { 
                    Data = new { 
                                  group1 = new {
                                              item01 = "this is the first item",
                                              item02 = "this is the second item",
                                              item03 = "this is the third item"
                                  },
                                  group2 = new {
                                              item04 = "this is the fourth item",
                                              item05 = "this is the fifth item"
                                  }
                               }
                   };

0 个答案:

没有答案