如果我有这个结构
var data =
{
"people": [
{ "name" : "John", "id" : 1 },
{ "name" : "Marc", "id" : 2 }
]
}
我想在JavaScript中添加更多元素,特别是在jQuery中,然后像这样发送它
var dataString = JSON.stringify(data);
$.post('some.php', { data: dataString}, showResult, "text");
答案 0 :(得分:3)
var data =
{
"people": [
{ "name" : "John", "id" : 1 },
{ "name" : "Marc", "id" : 2 }
]
}
data["people"].push({"name": "foo", "id": 3});
console.log(data);