JavaScript building a JSON string building json string c#,building json string in java,generate

I have a two part question (Very new to JSON)

  1. I need to build a json object out of attr 'data-id'. Can a JSON object be a single 'array' of numbers?
  2. I have got the code for this but I am struggling to build the JSON object, as follows:

code:

var displayed = {};
$('table#livefeed tr').each(function (i) {
    var peopleID = $(this).attr("data-id");
    //console.log("id: " + peopleID);
    if(peopleID!="undefined") displayed += peopleID;
});
console.log(displayed);

However this does not work properly, I just end up with string of objects added together.

Answer:1

A JSON object can be an array of numbers.

Try something like this:

var displayed = [];
$('table#livefeed tr').each(function (i) {
    var peopleID = $(this).attr("data-id");
    if(peopleID!="undefined") 
        displayed.push(peopleID);
});
console.log(displayed);

To turn it into JSON,

JSON.stringify(displayed);
Answer:2

I am writing a plugin for showing ajax content.It is wrapped in a ajax-content-wrap.I have applied jquery animate() but not smooth with auto height.And fade() function is also animating.But when i use ...

I am writing a plugin for showing ajax content.It is wrapped in a ajax-content-wrap.I have applied jquery animate() but not smooth with auto height.And fade() function is also animating.But when i use ...

I have been trying to write a python script to allow me to harvest QR codes from whatsapp web. I use selenium but can't seem to get it to write. The QR image is a PNG generated by a javascript live (...

I have been trying to write a python script to allow me to harvest QR codes from whatsapp web. I use selenium but can't seem to get it to write. The QR image is a PNG generated by a javascript live (...

I am customising Sage CRM, so I have no control over the HTML that is written and can't add IDs or class's to the table layouts the CRM spits out. I want to hide a higher (not top) level table based ...

I am customising Sage CRM, so I have no control over the HTML that is written and can't add IDs or class's to the table layouts the CRM spits out. I want to hide a higher (not top) level table based ...

  1. jquery find parent with class
  2. jquery find parent element
  3. jquery find parent tr
  4. jquery find parent div
  5. jquery find parent form
  6. jquery find parent with attribute
  7. jquery find parent with id
  8. jquery find parent with class name
  9. jquery find parent td
  10. jquery find parent table
  11. jquery find parent li
  12. jquery find parent of parent
  13. jquery find parent row
  14. jquery find parent matching selector
  15. jquery find parent sibling child
  16. jquery find parent or grandparent
  17. jquery find parent with data attribute
  18. jquery find parent until
  19. jquery find parent sibling
  20. jquery find parent tr of td

I hope questions from beginners are acceptable. I don't mind studying, but based on research so far, I'm not sure where to even begin........ I'm in need of a script that can fit into a small URI ...

I hope questions from beginners are acceptable. I don't mind studying, but based on research so far, I'm not sure where to even begin........ I'm in need of a script that can fit into a small URI ...