1

I'm new to jQuery!

Is there a way to convert table element data to JSON? see sample image below.

enter image description here

The JSON result was on the #result div.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
jrsalunga
  • 409
  • 2
  • 8
  • 20
  • Check here: [Iterate through HTML table using jQuery, converting the data in the table into JSON][1] Although if you yourself control the generation of this table, I'd recommend something like knockout (http://knockoutjs.com/) [1]: http://stackoverflow.com/questions/1872485/iterate-through-html-table-using-jquery-converting-the-data-in-the-table-into-j – Stephen Byrne Jan 18 '13 at 00:44

1 Answers1

1
var arr = $('tr').map(function () {
    var o = {
        "apvhdrid": this.parentNode.parentNode.dataset.apvhdrid,
        "id": this.dataset.id
    };
    $('td', this).each(function () {
        for (key in this.dataset) {
            o[key] = this.dataset[key];
        }
    })
    return o;
}).get();

$('#result').text(JSON.stringify(arr));

http://jsfiddle.net/pE8Hu/

Ram
  • 143,282
  • 16
  • 168
  • 197