js前端获取表格中的数据生成对应的json数组?急!!
html中的数据:
<div id="kysite_listcontent">
<table cellspacing=1 cellpadding=1 align=center border=0>
<tbody>
<tr>
<td><a title=广州市-白云区 href="http://xxx.com" target=_blank>白云1</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安1</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安2</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安3</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安4</a></td>
</tr>
<tr>
<td><a title=深圳市-南山区 href="http://xxx.com" target=_blank>南山1</a></td>
</tr>
<tr>
<td><a title=深圳市-福田区 href="http://xxx.com" target=_blank>福田1</a></td>
</tr>
<tr>
<td><a title=深圳市-龙岗区 href="http://xxx.com" target=_blank>龙岗</a></td>
</tr>
<tr>
<td><a title=深圳市-龙岗区 href="http://xxx.com" target=_blank>龙岗</A></td>
</tr>
<tr>
<td><a title=上海-浦东新区 href="http://xxx.com" target=_blank>浦东</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安</a></td>
</tr>
<tr>
<td><a title=深圳市-南山区 href="http://xxx.com" target=_blank>南山</a></td>
</tr>
<tr>
<td><a title="" href="http://xxx.com" target=_blank>福田</a></td>
</tr>
<tr></tr>
</tbody>
</table>
</div>
想要生成类似的json数组:
var arrObj=[
{title:"深圳",info:[
{quyu:"宝安区",wd:["宝安1|http://xxx.com","宝安2|http://xxx.com","宝安3|http://xxx.com","宝安4|http://xxx.com","宝安5|http://xxx.com","宝安6|http://xxx.com"]},{quyu:"南山区",wd:["南山1|http://xxx.com","南山2|http://xxx.com","南山3|http://xxx.com"]}
,{quyu:"福田区",wd:["福田1|http://xxx.com","福田2|http://xxx.com","福田3|http://xxx.com"]}
]
},
{title:"上海",info:[
{quyu:"浦东新区1",wd:["浦东1|http://xxx.com","浦东2|http://xxx.com","浦东3|http://xxx.com"]},{quyu:"浦东新区2",wd:["浦东4|http://xxx.com","浦东5|http://xxx.com","浦东6|http://xxx.com"]}
,{quyu:"浦东新区3",wd:["福田7|http://xxx.com","福田8|http://xxx.com","福田9|http://xxx.com"]}
]
},
{title:"广州",info:[
{quyu:"白云区1",wd:["白云1|http://xxx.com","白云2|http://xxx.com","白云3|http://xxx.com"]},{quyu:"白云区2",wd:["白云4|http://xxx.com","白云5|http://xxx.com","白云6|http://xxx.com"]}
,{quyu:"白云区3",wd:["白云7|http://xxx.com","白云8|http://xxx.com","白云9|http://xxx.com"]}
]
}
];
我要展示到页面上显示为:

<div id="kysite_listcontent">
<table cellspacing=1 cellpadding=1 align=center border=0>
<tbody>
<tr>
<td><a title=广州市-白云区 href="http://xxx.com" target=_blank>白云1</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安1</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安2</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安3</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安4</a></td>
</tr>
<tr>
<td><a title=深圳市-南山区 href="http://xxx.com" target=_blank>南山1</a></td>
</tr>
<tr>
<td><a title=深圳市-福田区 href="http://xxx.com" target=_blank>福田1</a></td>
</tr>
<tr>
<td><a title=深圳市-龙岗区 href="http://xxx.com" target=_blank>龙岗</a></td>
</tr>
<tr>
<td><a title=深圳市-龙岗区 href="http://xxx.com" target=_blank>龙岗</A></td>
</tr>
<tr>
<td><a title=上海-浦东新区 href="http://xxx.com" target=_blank>浦东</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安</a></td>
</tr>
<tr>
<td><a title=深圳市-南山区 href="http://xxx.com" target=_blank>南山</a></td>
</tr>
<tr>
<td><a title="" href="http://xxx.com" target=_blank>福田</a></td>
</tr>
<tr></tr>
</tbody>
</table>
</div>
想要生成类似的json数组:
var arrObj=[
{title:"深圳",info:[
{quyu:"宝安区",wd:["宝安1|http://xxx.com","宝安2|http://xxx.com","宝安3|http://xxx.com","宝安4|http://xxx.com","宝安5|http://xxx.com","宝安6|http://xxx.com"]},{quyu:"南山区",wd:["南山1|http://xxx.com","南山2|http://xxx.com","南山3|http://xxx.com"]}
,{quyu:"福田区",wd:["福田1|http://xxx.com","福田2|http://xxx.com","福田3|http://xxx.com"]}
]
},
{title:"上海",info:[
{quyu:"浦东新区1",wd:["浦东1|http://xxx.com","浦东2|http://xxx.com","浦东3|http://xxx.com"]},{quyu:"浦东新区2",wd:["浦东4|http://xxx.com","浦东5|http://xxx.com","浦东6|http://xxx.com"]}
,{quyu:"浦东新区3",wd:["福田7|http://xxx.com","福田8|http://xxx.com","福田9|http://xxx.com"]}
]
},
{title:"广州",info:[
{quyu:"白云区1",wd:["白云1|http://xxx.com","白云2|http://xxx.com","白云3|http://xxx.com"]},{quyu:"白云区2",wd:["白云4|http://xxx.com","白云5|http://xxx.com","白云6|http://xxx.com"]}
,{quyu:"白云区3",wd:["白云7|http://xxx.com","白云8|http://xxx.com","白云9|http://xxx.com"]}
]
}
];
我要展示到页面上显示为:

...全文
相关推荐
JS自动把JSON数据转换成表格
根据给定的信息,本文将详细解释如何通过JavaScript(简称JS)将JSON数据转换为表格,包括HTML字符串形式和DOM对象形式。此方法适用于快速展示JSON数据,并可方便地集成到Web应用中。
基于javascript,ajax,json的在前端动态显示你的任何表格数据
= JsonConvert.SerializeObject(rows);return json;```前端接收到JSON数据后,可以通过JavaScript的数组方法和DOM操作,将数据动态地插入到HTML
js 获取json数组里面数组的长度实例
然而,与JavaScript数组不同,JSON对象并不直接提供`.length`属性来获取其包含元素的数量。在本文中,我们将探讨如何在JavaScript中获取JSON数组内嵌套数组的长度。
js获取json中key所对应的value值的简单方法
在JavaScript中,JSON被广泛用于数据传输。因此,在处理JSON数据时,经常需要获取JSON对象中key所对应的value值。
JS遍历JSON数组及获取JSON数组长度操作示例【测试可用】
JS遍历JSON数组及获取JSON数组长度操作示例涉及JavaScript中处理JSON数据类型的基础操作。


