将html table中的数据封装成json格式数据
var tab=document.getElementById("table1");
var rows=tab.rows;
//alert(rows.length);
var txt = "[";
for(var i=2;i<rows.length;i++)
{
var r = "[";
for(var j=0;j<rows[i].cells.length;j++)
{
// alert("第"+(i+1)+"行,第"+(j+1)+"列的值是:"+rows[i].cells[j].innerHTML);
r += "\"" + rows[i].cells[j].innerHTML+"\",";
}
r = r.substring(0, r.length - 1);
r += "],";
txt += r;
}
txt = txt.substring(0, txt.length - 1);
txt += "]";
// alert(txt);
JSONArray jsonarray = JSONArray.fromObject(txt);
for(int i=0;i<jsonarray.size();i++){
log.debug(jsonarray.get(i));
JSONArray jsoncol = JSONArray.fromObject(jsonarray.get(i));
for(int j=0;j<jsoncol.size();j++){
log.debug(jsoncol.get(j));
}
}