I have this json data that I'm trying to put into an html table:
{
"users":{
"key":[
"3128",
"3108"
],
"name":[
"jason",
"fred"
]
}
}
I wanted to make both key and name to separate columns in the table. I'm using this jquery code. Its placing the data properly in the in each column, however its duplicating the data. I'm guessing its because I'm looping through multiple times.
var url = "http://localhost/test.php";
$.getJSON(url,function(data){
var table = '<table><thead><tr><th>Key</th><th>Name</th></tr></thead><tbody>';
$.each(data, function(i, param) {
$.each(param['key'], function(l, k) {
$.each(param['name'], function(l, p) {
table +="<tr><td>" + k + "</td>"+"<td>" + p + "</td></tr>";
});
});
});
table += '</tbody></table>';
$("#jsondata").html( table );
});
How do I stop duplicating the data in the columns I'm creating?
Help is greatly appreciated!