js创建jsonArray

不多说,直接上代码了。

1.前台生成:

		var jsonstr="[]";
			var jsonarray = eval('('+jsonstr+')');
			
			var formdata1 = {
					"activeproid" : activeproid[0].value,
					"activeproPrice" : activeproPrice[0].value,
					"activeproKucun" : activeproKucun[0].value,
					"activeproXiangou" : activeproXiangou[0].value,
					"activeproStart" : activeproStart[0].value,
					"activeproend" : activeproend[0].value
				};
			var formdata2 = {
					"activeproid" : activeproid[1].value,
					"activeproPrice" : activeproPrice[1].value,
					"activeproKucun" : activeproKucun[1].value,
					"activeproXiangou" : activeproXiangou[1].value,
					"activeproStart" : activeproStart[1].value,
					"activeproend" : activeproend[1].value
				};
	
			jsonarray.push(formdata1);
			jsonarray.push(formdata2);
				
			var formdata = {
					"postMes":jsonarray,
					"actId":actId
				};
			
			$.ajax({
		        type: "POST",
		        url: "url",
		        contentType: "application/json; charset=utf-8",
		        data: JSON.stringify(formdata),
		        dataType: "json",
		        success: function (message) {
		        	
		        },
		        error: function (message) {
		            $("#request-process-patent").html("提交数据失败!");
		        }
		  

2.后台解析:

                JsonNode in = request().body().asJson();//接收到的推送信息
		Logger.info("收到的推送信息" + in.toString());
		String actId = in.get("actId").textValue();
		Iterator trades = in.findValue("postMes").elements();
	
		while (trades.hasNext()) {
			JsonNode trade = trades.next();
			String activeproid = trade.get("activeproid").textValue();
			Logger.info("id:" + activeproid);
			String activeproPrice = trade.get("activeproPrice").textValue();
			Logger.info("价格:" + activeproPrice);
			。。。
			
		}


你可能感兴趣的:(前端技术)