如何将包含HTML标记的字符串转换为JSON?
任何链接或评论?
答案 0 :(得分:2)
<?php
$string = "<table><tr><td>1231</td></tr></table>";
json_encode($string);
?>
答案 1 :(得分:0)
假设您在浏览器中运行此功能:
var rows = document.getElementById('table-id').rows,
l = rows.length,
i = 0,
array = [];
for ( ; i < l; i++ )
{
array.push( getRowArray(rows[i]) );
}
function getRowArray ( row )
{
var array = [],
cells = row.childNodes,
l = cells.length,
i = 0;
for ( ; i < l; i++ )
{
cells[i].nodeType == 1 && array.push( cells[i].textContent );
}
return array;
}