jsp页面中,js如何解析json数组

[
{
"name": "张三",
"birthday": "1947-05-03"
},
{
"name": "李四",
"birthday": "1929-01-01"
}
]
上诉的json数组(后台给的)如何在下面的table中显示?
<table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody></tbody></table>

给table个id

var data = [{"name": "张三","birthday": "1947-05-03"},{"name": "李四","birthday": "1929-01-01"}];
var table = document.getElementById("table");
var tbody = table.tBodies.item(0) || table;
for(var i = 0,l=data.length;i<l;i++){
    var tr_row = document.createElement("tr");
    var td_name = document.createElement("td");
    var td_birthday = document.createElement("td");
    td_name.innerText = data[i].name;
    td_birthday.innerText = data[i].birthday;
    tr_row.appendChild(td_name);
    tr_row.appendChild(td_birthday);
    tbody.appendChild(tr_row);
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答