leo*_*ora 4 .net c# asp.net-mvc json jqgrid
我试图模仿他们使用硬编码JSON的例子
{
"page": 1,
"total": 1,
"records": 2,
"rows": [
{"id": 1, "cell": ["1", "Super Item", "300", 0, null, false, false]},
{"id": 2, "cell": ["2", "Item 1", "100", 1, 1, false, false]},
{"id": 3, "cell": ["3", "Sub Item 1", "50", 2, 2, true, true]},
{"id": 4, "cell": ["4", "Sub Item 2", "25", 2, 2, false, false]},
{"id": 5, "cell": ["5", "Sub-sub Item 1", "25", 3, 4, true, true]},
{"id": 6, "cell": ["6", "Sub Item 3", "25", 2, 2, true, true]},
{"id": 7, "cell": ["7", "Item 2", "200", 1, 1, false, false]},
{"id": 8, "cell": ["8", "Sub Item 1", "100", 2, 7, false, false]},
{"id": 9, "cell": ["9", "Sub-sub Item 1", "50", 3, 8, true, true]},
{"id": 10, "cell": ["10", "Sub-sub Item 2", "50", 3, 8, true, true]},
{"id": 11, "cell": ["11", "Sub Item 2", "100", 2, 7, true, true]}
]
}
Run Code Online (Sandbox Code Playgroud)
但我需要从C#生成这个.有没有关于在C#中生成以上内容的最佳方法的建议?
Guf*_*ffa 11
该Controller班有一个Json是对象串行化JSON作为,所以在你的操作方法您刚才创建对象并调用该方法方法:
public ActionResult GetData() {
return Json(
new {
page = 1,
total = 1,
records = 2,
rows = new[] {
new { id = 1, cell = new object[] { "1", "Super Item", "300", 0, null, false, false } },
new { id = 2, cell = new object[] { "2", "Item 1", "100", 1, 1, false, false } },
new { id = 3, cell = new object[] { "3", "Sub Item 1", "50", 2, 2, true, true } },
new { id = 4, cell = new object[] { "4", "Sub Item 2", "25", 2, 2, false, false } },
new { id = 5, cell = new object[] { "5", "Sub-sub Item 1", "25", 3, 4, true, true } },
new { id = 6, cell = new object[] { "6", "Sub Item 3", "25", 2, 2, true, true } },
new { id = 7, cell = new object[] { "7", "Item 2", "200", 1, 1, false, false } },
new { id = 8, cell = new object[] { "8", "Sub Item 1", "100", 2, 7, false, false } },
new { id = 9, cell = new object[] { "9", "Sub-sub Item 1", "50", 3, 8, true, true } },
new { id = 10, cell = new object[] { "10", "Sub-sub Item 2", "50", 3, 8, true, true } },
new { id = 11, cell = new object[] { "11", "Sub Item 2", "100", 2, 7, true, true } }
}
}
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2796 次 |
| 最近记录: |