Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将html表解析为json jquery_Javascript_Jquery - Fatal编程技术网

Javascript 将html表解析为json jquery

Javascript 将html表解析为json jquery,javascript,jquery,Javascript,Jquery,如何将html表转换为json数据?我需要这样的结果。代码必须在jquery上 {"status":"ok","data":[{"name":"Haroldas","number":444,"address":"address"},{"name":"tom","number":999,"address":"rrr"},{"name":"ted","number":333,"address":"kkk"}]} 这是我的桌子: 名称 数 地址 哈罗德 444 地址 特德 333 kkk 汤姆

如何将html表转换为json数据?我需要这样的结果。代码必须在jquery上

{"status":"ok","data":[{"name":"Haroldas","number":444,"address":"address"},{"name":"tom","number":999,"address":"rrr"},{"name":"ted","number":333,"address":"kkk"}]}
这是我的桌子:


名称
数
地址
哈罗德
444
地址
特德
333
kkk
汤姆
999
存款准备金率

您可以这样做:

$.fn.toJson=function(){
如果(!this.is('table')){
返回;
}
var结果=[],
标题=[];
this.find('thead tr th')。每个(函数(索引、值){
headers.push($(value.text());
});
this.find('tbody tr')。每个(函数(indx,obj){
var行={};
var tds=$(obj).children('td');
标题.forEach(功能(键、索引){
var值=tds.eq(index.text();
行[键]=值;
});
结果:推动(世界其他地区);
});
返回结果;
}
$(函数(){
$('#results').html(JSON.stringify($('#excel').toJson(),null,'\t'));
});

名称
数
地址
哈罗德
444
地址
特德
333
kkk
汤姆
999
存款准备金率

向我们展示您的努力!!你能给我们看看你的JS代码吗?重复??不,这是毫无疑问的。这是我的jquery:$.makeTableToArray=function(){var table=$('#excel tr').map(function(){return$(this).find('td').map(function(){return$(this.html();}).get();}).get();return table;};我不能添加更多的代码后