jquery解析json数组然后自动生成table,下面是我解析的,它带有Object
hydatasparent[objectObject][objectObject][objectObject][objectObject][objectObject][o...
hydatas parent
[object Object] [object Object]
[object Object] [object Object]
[object Object] [object Object]
[object Object] [object Object]
[object Object] [object Object]
json数组如下:var testArray=[{"hydatas":{"INDUSTRY_CODE":"GH2014010","ID":136909,"INDUSTRY_NAME":"食品与药物零售"},"parent":{"name":"消费服务","ID":"136907"}},{"hydatas":{"INDUSTRY_CODE":"GH2014009","ID":136908,"INDUSTRY_NAME":"旅游"},"parent":{"name":"消费服务","ID":"136907"}},{"hydatas":{"INDUSTRY_CODE":"GH2014006","ID":136905,"INDUSTRY_NAME":"饮食"},"parent":{"name":"生活消费类","ID":"136906"}},{"hydatas":{"INDUSTRY_CODE":"GH2014002","ID":136901,"INDUSTRY_NAME":"饮料"},"parent":{"name":"生活消费类","ID":"136906"}},{"hydatas":{"INDUSTRY_CODE":"GH2014003","ID":136902,"INDUSTRY_NAME":"食品"},"parent":{"name":"生活消费类","ID":"136906"}}];
这是我网上找的代码, 展开
[object Object] [object Object]
[object Object] [object Object]
[object Object] [object Object]
[object Object] [object Object]
[object Object] [object Object]
json数组如下:var testArray=[{"hydatas":{"INDUSTRY_CODE":"GH2014010","ID":136909,"INDUSTRY_NAME":"食品与药物零售"},"parent":{"name":"消费服务","ID":"136907"}},{"hydatas":{"INDUSTRY_CODE":"GH2014009","ID":136908,"INDUSTRY_NAME":"旅游"},"parent":{"name":"消费服务","ID":"136907"}},{"hydatas":{"INDUSTRY_CODE":"GH2014006","ID":136905,"INDUSTRY_NAME":"饮食"},"parent":{"name":"生活消费类","ID":"136906"}},{"hydatas":{"INDUSTRY_CODE":"GH2014002","ID":136901,"INDUSTRY_NAME":"饮料"},"parent":{"name":"生活消费类","ID":"136906"}},{"hydatas":{"INDUSTRY_CODE":"GH2014003","ID":136902,"INDUSTRY_NAME":"食品"},"parent":{"name":"生活消费类","ID":"136906"}}];
这是我网上找的代码, 展开
展开全部
var html="";
for (var i = 0; i < testArray.length; i++) {
alert(testArray[i].hydatas.INDUSTRY_CODE);
//以此类推
}
//我不知道你的表格想生成什么样的
更多追问追答
追答
var html = "<table border=\"1\">";
for (var i = 0; i < testArray.length; i++) {
html += "<tr>";
//以下是取hydatas
html += "<td>" + testArray[i].hydatas.INDUSTRY_CODE + "</td>";
html += "<td>" + testArray[i].hydatas.ID + "</td>";
html += "<td>" + testArray[i].hydatas.INDUSTRY_NAME + "</td>";
//取hydatas完
//以下是取parent
html += "<td>" + testArray[i].parent.name + "</td>";
html += "<td>" + testArray[i].parent.ID + "</td>";
//取parent完
html += "</tr>";
}
$("div").html(html+"</table>");
//大致是这样的,你自己在修改下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询