怎样在asp.net mvc中一次http请求返回多个json对象?

来源:互联网 发布:sql to_char 什么 要 编辑:程序博客网 时间:2024/06/07 02:20

废话不说,直接上代码

public ActionResult GetUnreadMailJsonByApp()
        {
            string userId = OperatorProvider.Provider.Current().UserId;
            var data = emailContentBLL.GetUnreadMail( userId);
            
            var JsonData = new
            {
                rows = data,
                total = pagination.total,
                page = pagination.page,
                records = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };
            return Content(JsonData.ToJson());
     }

把 上面的多个对象通过JsonData进行封装。

当然,自己按照Json格式封装也可以,就是拼接字符串,格式为  {"obj1":"xxx","obj2":{"ff":"ff1","ffse","ffwwe"}},如果想看自己的Json字符串格式对不对,有在线测试的网站,直接复制过去就可以了。

阅读全文
0 0
原创粉丝点击