我正在尝试从 ASP.NET MVC 1.0 Web 应用程序中的 JSON 页面解析数据。我需要在页面加载时将这些数据显示在表格中,但我遇到了很多麻烦,主要是因为我以前从未使用过 JSON。 JQuery 网站也提供了非常糟糕的例子。这是我到目前为止所拥有的,我需要编写函数的帮助:
$("document").ready(function() {
$.getJSON("http://localhost:1909/encoders",
function(data) {
$.each(data.items, function() {
});
});
});
上面的 URL 当前仅显示 JSON,我从 SQL Server 获取用于生成 JSON 的两列是 EncoderName 和 EncoderStatus。 id 是displayencoders。
谢谢!
编辑: 我的 Controller 看起来像这样:
[UrlRoute(Name = "GetEncoders", Path = "encoders")]
public ActionResult GetEncoders() {
var encoders = Database.GetEncoders();
return Json(encoders);
}
编译时我的/encoders/看起来像:
{
* EncoderName: "rmcp2-encoder"
* EncoderStatus: "inactive"
}
最佳答案
$("document").ready(function() {
$.getJSON("http://localhost:1909/encoders", function(data) {
$("#div-my-table").text("<table>");
$.each(data, function(i, item) {
$("#div-my-table").append("<tr><td>" + item.EncoderName +"</td><td>" + item.EncoderStatus + "</td></tr>");
});
$("#div-my-table").append("</table>");
});
});
关于jquery - Json:使用 JQuery 解析以 HTML 形式显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2067078/