前端
var PaxNames = new Array();
var PaxIds = new Array();
for(var i= 1; i<=3;i++){
var paxName = {};
var paxId = $('#paxId_'+i+'').val();
var paxType = $('#paxType_'+i+'').val();
var userName = $('#userName_'+i+'').val();
创建集合元素并赋值
paxName.PaxId=paxId;
paxName.PaxType=paxType;
paxName.content=userName;
PaxNames.push(paxName);
}
前端转换成JSON
JSON.stringify(PaxNames)
后台用String PaxNames接收。用JSONArray转换成List
1、用Map<String.Object>接收
JSONArray jArray= JSONArray.fromObject(PaxNames);
Collection collection = JSONArray.toCollection(jArray, Map.class);Iterator it = collection.iterator();
while (it.hasNext()) {
Map<String, Object> map = (Map<String, Object>) it.next();
List.add(map);
}
2、 用Bean接收
JSONArray jArray= JSONArray.fromObject(PaxNames);
Collection collection = JSONArray.toCollection(jArray, Bean.class);Iterator it = collection.iterator();
while (it.hasNext()) {
Bean bean= (Bean) it.next();
List.add(map);
}