前段方法:
var map={}
var jss = JSON.stringify(map);
后台解析
JSONObject jb = JSONObject.fromObject(data);
getString(String key); 获取字符串
getJSONArray(String key); 获取数组
示例:
前端:
function submit(){
if(validform()){
var accountList=[];
var moneyList=[];
var map = {};
map["nowdate"] =$("#nowdate").val();
map["FNumber"] =$("#FID").val();
var x2 = 0;
var bmoney2 = 0;
for(var i=0;i<len;i++)
{
if(($("#un_"+i).val()!="")&&($("#un_"+i).val()!="0"))
{
accountList.push($("#name_"+i).val());
bmoney2 = parseFloat($("#un_"+i).val());
moneyList.push(bmoney2);
//alert(bmoney2);
x2 += bmoney2;
}
}
map["price"] =x2;
map["acctList"]=accountList;
map["moneyList"]=moneyList;
var jss = JSON.stringify(map);
$.ajax({
type: 'POST',
url:"XXXX,
data: {data:jss},
dataType: "json",
success: function(data){
}
});
}
};
后台:
String data=request.getParameter("data"); JSONObject jb = JSONObject.fromObject(data); String price=jb.getString("price");//金额 String nowdate=jb.getString("nowdate");//支取时间 String FNumber=jb.getString("FNumber");//客户ID // String FAttachments=jb.getString("FAttachments");//单据数量 JSONArray bankList = jb.getJSONArray("acctList");//银行账户信息 JSONArray custormList = jb.getJSONArray("moneyList");//客户账户信息