0
我一直在寻找解决方案,但没有成功。如何保存JSON对象列表
我已经生成对象的JSON列表:
[
{
Email : "[email protected]",
Aanwezigheid : "nodig"
}, {
Email : "[email protected]",
Aanwezigheid : "gewenst"
}, {
Email : "[email protected]",
Aanwezigheid : "info"
}
]
型号:
public class Invitee
{
public int Id { get; set; }
public int AppId { get; set; }
public string Email { get; set; }
public string Presence { get; set; }
};
jQuery的AJAX调用:
$.ajax({
url: '@Url.Action("NewAppSave","App")',
dataType: "json",
type: "POST",
accept: 'appication/json; charset=utf-8',
cache: false,
data: jsonData,
success: function (data) {
if (data.success) {
alert("Met succes !");
}
},
error: function (xhr) {
alert('error');
}
});
什么是正确的方式来保存这个数据到一个SQL Server数据库? 所有数据库字段都与模型中的数据库完全匹配。
您需要对数据进行字符串化 - 'data:JSON.stringify(jsonData),'但是您的模型不包含名为'Aanwezigheid'的属性。 –
修改您的js对象以包含'Presence'而不是'Aanwezigheid'。例如。 { 电子邮件:“[email protected]”, 存在:“nodig” } –
您需要一个“实体数据模型”。可以将整个json序列化并作为字符串存储在表列中。 – Sajal