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.

1
  • 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 (knockoutjs.com) [1]: stackoverflow.com/questions/1872485/… Commented Jan 18, 2013 at 0:44

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

magic! thank you for that! this is what i needed to do this! jsfiddle.net/jrsalunga/bPHkW

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.