I Have a JSON data file like below and I would like to load all objects under the utility
into a table but I am not even able to load first row into the table!
Can you please take a look at this and let me know what I am doing wrong? and how I can loop trough all utility
objects and load them in a seperate table <tr>
var data = {
"utility": {
"Water": {
"account": "99999",
"balance": "5555",
"owner": "Fred"
},
"Phone": {
"account": "7777",
"balance": "6666",
"owner": "Mark"
},
"Power": {
"account": "A9885",
"balance": "2222",
"owner": "Suzan"
}
},
"clients": {
"David": {
"account": "99999",
"balance": "5555",
"Date": "Jan 11"
},
"George": {
"account": "7777",
"balance": "6666",
"Date": "March 22"
},
"Marco": {
"account": "A9885",
"balance": "2222",
"Date": "Feb 25"
}
}
}
var obj = JSON.parse(data);
$(".container").append(
'<table class="table table-hover"><tr><td>' +
obj.Water.account +
'</td><td>99999</td><td>5555</td><td>Fred</td></tr></table>'
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container"></div>