To pass an array of experience in the foreground to the background to go, if you have been spliced with a string of words, I feel a little less easy to use in the project, with the thought pass arrays. My approach is to first save to pass an array of values, and then turn the array into JSON format spread to the background.
1, js codes:
var table = document.getElementById("gtable");
var obj = "";
var array = new Array();
for(var i = 1;i<=9;i++){
if(table.rows.cells[1].innerHTML != "" && table.rows.cells[1].innerHTML!=" "){
obj = new Object();
obj.num = table.rows.cells[0].innerHTML;
obj.candidate = table.rows.cells[1].innerHTML;
array.push(obj);
}
}
This is to get the value of the entire table inside.
Transmission values: textInfo: encodeURIComponent (JSON.stringify (array)), encodeURIComponent transcoding, to prevent back to Chinese garbled.
The most important thing is JSON.stringify (array) This array is converted into writing JSON format. First import json2.js, byhttps://github.com/douglascrockford/JSON-js/blob/master/json2.js 。
2, java codes
Object [] list = JSONUtils.getStringArray4Json (URLDecoder.decode (request.getParameter ( "textInfo"), "UTF-8"))); textInfo variable is transferred from the front.
JSONUtils.getStringArray4Json method:
/** *//**
* From parsing json array java string array
* @param jsonString
* @return
*/
public static String[] getStringArray4Json(String jsonString){
JSONArray jsonArray = JSONArray.fromObject(jsonString);
String[] stringArray = new String[jsonArray.size()];
for( int i = 0 ; i<jsonArray.size() ; i++ ){
stringArray = jsonArray.getString(i);
}
return stringArray;
}
Object spooler first converted to an array of objects, and then through the array list
for (int j = 0; j < list.length; j++) {
String textInfo = list[j].toString();
Map textInfoMap = JSONUtils.getMap4Json(textInfo);
String answerId = textInfoMap.get("num").toString();
String cdate=textInfoMap.get("candidate ").toString();
System.out.println(answerId+","+cdate );
}
So that you can get the front desk pass over each value of the array. This method is also a reference written by someone else, learn from others, a detailed record of them before they go after their own forgotten