我正在尝试按如下方式对数组进行 json 序列化:
function postToDrupal(contacts, source, owner) {
(function ($) {
var contact, name, email, entry;
var emails = [];
var post_object = {};
for (var i = 0; i < contacts.length; i++) {
contact = contacts[i];
emails[i] = {};
emails[i]['name'] = contact.fullName();
emails[i]['email'] = contact.selectedEmail();
console.log(contacts.length)
}
post_object['emails']=emails;
post_object['source']=source;
post_object['owner']=owner;
$.post("/cloudsponge-post",JSON.stringify(post_object),function(data) {
window.location.href = "/after-import";
});
}(jQuery));
}
问题是,帖子回来是空的。没有 JSON.stringify() 我得到了所有的元素(但是有成千上万的元素,这可能会达到某些服务器的限制,因此需要对它们进行序列化)。任何帮助将非常感激。