试图创建一个我可以转换为Json的Javascript数组

时间:2015-02-23 20:05:56

标签: javascript json

希望有人可以帮助我。我有以下函数,使用javascript;

在JSON.stringify之后返回此函数

{"tablerows":[{"colone":"test","colthree:":"testf","row:0},{"colone":"testd","row":1}]}然而,我试图找到能够为行提供另一个级别的东西,这样就好了 0行
row0.colone:测试
row0.colthree:testf ROW1 row1.colone:testd
        for(var i = 0; i< rowCount; i ++){              var row = table.rows [i];              var currentrowcellcount = $('td',row).length;

          if (currentrowcellcount == 4) {
          var colone = row.cells[0].childNodes[0].childNodes  [0].innerHTML;

          var coltwo = row.cells[1].childNodes[0].childNodes[0].innerHTML;

          var colthree = row.cells[2].childNodes[0].childNodes[0].innerHTML;
                tablerow = {
                    'colone': colone,
                    'coltwo': coltwo,
                    'colthree': colthree
                }
                container.tablerows.push(tablerow);
                container.tablerows[i].row = i;
            }
            else if (currentrowcellcount == 2) {
                var fieldnameone = row.cells[0].childNodes[0].childNodes[0].innerHTML;

            }
        }
        $('#SuccessUpdate').fadeIn(500).delay(500).fadeOut(500);
        alert(JSON.stringify(container));

1 个答案:

答案 0 :(得分:0)

在这个问题中缺少报价。我得到了json值:

var test = {"tablerows":[{"colone":"test","colthree:":"testf","row":0},{"colone":"testd","row":1}]};

console.log(test.tablerows[0].colone); 
console.log(test.tablerows[1].row); 

请参阅jsfiddle:http://jsfiddle.net/5b4608b9/