gpt4 book ai didi

javascript - JSON.stringify 忽略嵌套对象

转载 作者:行者123 更新时间:2023-12-03 07:23:10 24 4
gpt4 key购买 nike

我目前正在解决将 JSON 数据发送到我的 Controller 的问题。

我发现当传递一个包含嵌套对象的对象时,嵌套对象将为空。我不知道我错过了什么......

我的服务器端看起来像这样:

[HttpPost]
public ActionResult ApplyChanges(List<Change> pChanges)
{
//the Issue occurs here in every object of pChanges:
//IgnoreFlag was populated correctly, but the Detection Object is null...?
}

public class Change
{
public Detection Detection { get; set; }
public bool IgnoreFlag { get; set; }
}

我的客户端看起来像这样:

var data = [
{
"Detection": {
"PropertyOld": 1,
"PropertyNew": 2,
},
"IgnoreFlag": true
},
{
"Detection": {
"PropertyOld": 3,
"PropertyNew": 4,
},
"IgnoreFlag": false
}
]

$.ajax({
type: "POST",
url: "/Url/To/ApplyChanges",
data: JSON.stringify({"pChanges": data}),
contentType: "application/json",
success: function (data, textStatus, jqXHR) {
//do something here
});

有人可以帮我解决这个问题吗?

最佳答案

使用

JSON.stringify(data) 

而不是使用

JSON.stringify({"pChanges": data})

关于javascript - JSON.stringify 忽略嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36115226/

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