-1

如何将包含 HTML 标签的字符串转换为 JSON?

任何链接或评论?

4

2 回答 2

2
<?php
  $string = "<table><tr><td>1231</td></tr></table>";
  json_encode($string);
?>
于 2013-07-03T04:17:15.177 回答
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;
}

这是小提琴:http: //jsfiddle.net/cqzqs/

于 2013-07-03T04:24:45.610 回答