I have a json file called example.js The contents of the file look like the below.
{
"name":"tom",
"age":38,
"gender":"male"
}
Using the example in the jQuery documentation as a guide
jQuery.getJSON("example.js", function (data) {
var items = [];
jQuery.each(data, function (key, val) {
items.push("<li id='" + key + "'>" + val + "</li>");
});
jQuery("<ul/>", {
"class": "my-new-list",
html: items.join("")
}).appendTo("body");
});
I can output all the values
<ul class="my-new-list">
<li id="name">tom</li>
<li id="age">38</li>
<li id="gender">male</li>
</ul>
However I can't find anywhere where I could just output the persons age for example.
I thought it would have something like age[0] in it but I can't seem to get anything to return when I try this?