小编syd*_*n21的帖子

如何在 ASP.NET Web API C# 中返回 JSON 数组

我想以以下格式返回(在网络浏览器中显示)json 数组。

{
    "RainfallAreaAVG": [
    {
        "AreaBbsID": "18",
        "DistCount": "1",
        "SubDistCount": "2",
        "Amount": "14",
        "Hail": "14",
        "ArealDetails": [
                {
                    "DistBbsID": "101",
                    "SubDistCount": "2",
                    "Amount": "14",
                    "Hail": "14",
                    "SubDistCount": "2",
                    "DistDetails": [
                        {
                            "SubDistBbsID": "101",
                            "Amount": "14",
                            "Hail": "2",
                            "Date": "2011-06-13"
                        },
                        {
                            "SubDistBbsID": "102",
                            "Amount": "10",
                            "Hail": "0",
                            "Date": "2011-06-13"
                        }
                    ]
                }
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我在 c# 和实体框架 5.0 中使用 asp.net web API (MVC),ADO.Net 实体数据模型作为我的模型。

我正在使用存储过程从 sql server 数据库获取数据:

在此处输入图片说明

目前我在我的控制器中使用下面的代码

namespace RainfallService.Controllers
{
    public class DistAVGController : ApiController …
Run Code Online (Sandbox Code Playgroud)

c# arrays json asp.net-web-api

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

arrays ×1

asp.net-web-api ×1

c# ×1

json ×1