gpt4 book ai didi

javascript - 如何操作JSON数据?

转载 作者:行者123 更新时间:2023-11-30 17:53:41 24 4
gpt4 key购买 nike

我在 asp.net mvc 4 中使用 angular.js。我试图通过 ajax 请求将 jason 数据传递到我的 Controller 的操作。这是我的脚本:

$scope.items = [
{ Name: "Name1", Email: "Email1", Address: "Address1", ContactNo: "contactNo1"},
{ Name: "Name2", Email: "Email2", Address: "Address2", ContactNo: "contactNo1"}
];

var users = JSON.stringify($scope.items);
$.ajax({
type: "POST",
url: "/Angular/saveData",
data: users,
dataType: "json",
success: function (msg) {
alert("Success");
},
error: function (msg) {
alert("Error");
}
});

我无法弄清楚操纵 jason 数据的“saveData”操作是什么?

最佳答案

Controller :

 [HttpPost]
public JsonResult saveData(DataClass[] items)
{

}

数据类:

public class DataClass {
public string Name {get; set; }
public string Email {get; set; }
public string Address {get; set; }
public string ContactNo {get; set; }
}

关于javascript - 如何操作JSON数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18458799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com