前台拼接json数组后台接受
前台代码 :
function makePicNameJson (){
var picNameListForJson = '{"picNameListForUpload": [';
$(".picInputsArae").children().each(function(){
picNameListForJson += '{"realName":"' + $(this).attr("id") +' ","fileName":"' + $(this).attr("class") +'" },';
});
picNameListForJson = picNameListForJson.substring(0,picNameListForJson.length-1);
picNameListForJson += ']}';
$("#picNameListForJson").attr("value",picNameListForJson);
//alert($("#picNameListForJson").val());
}
JSONObject.fromObject(picNameListArray.get(i)).get("fileName").toString()
后台接受处理 :
以string形式接受
JSONObject picNameListObject = JSONObject.fromObject(picNameListForJson);
JSONArray picNameListArray = picNameListObject.getJSONArray("picNameListForUpload");
for (int i = 0; i < picNameListArray.size(); i++) {
LwApplicateFinishiAddendum lwApplicateFinishiAddendum = new LwApplicateFinishiAddendum();
lwApplicateFinishiAddendum.setProjectId(projectId);
lwApplicateFinishiAddendum.setWorkerId(((UserInfoSS)getUser()).getId());
lwApplicateFinishiAddendum.setPicName(JSONObject.fromObject(picNameListArray.get(i)).get("realName").toString());
lwApplicateFinishiAddendum.setPicSysName(JSONObject.fromObject(picNameListArray.get(i)).get("fileName").toString());
lwApplicateFinishiAddendum.setPid(lwApplicateFinish.getId());
HibernateDAO.save(lwApplicateFinishiAddendum);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |