json转换数组为ajax发布

时间:2013-01-25 16:25:19

标签: json

任何人都知道我是怎么来的:

var guests = [];
for (var i = 0; i < parseInt(apartments) ; i++) {
     var pos = i + 1;

     var adults, children, infants;

     adults = $("#adults" + pos).val();
     infants = $("#infants" + pos).val();
     children = $("#children" + pos).val();
     guests.push({ Leg: pos, Adults: adults,
        Children: children, Infants: infants 
     });
}

对此事:

Guests: [{ Leg: "1", Adults: "2", Children: "0", Infants: "2" },{ Leg:
"2", Adults: "2", Children: "1", Infants: "0" }]

1 个答案:

答案 0 :(得分:0)

使用

JSON.stringify(guests);

我认为应该这样做。