html - Accessing JSON through Jquery returns "undefined" -
i'm writing small script take schedules json document , present them in list view. i'm having hard time getting right values return when access json document, in continues "undefined"
here's json doc.
{ "ferries": { "horseshoebay": {/*bunch of schedules here*/}, "departurebay": {/*bunch of schedules here*/}, "dukepoint": {/*bunch of schedules here*/}, } }
and here's js
$.getjson("includes/json/ferries.json", function(e){ var depart = e; $("#content").append("<ul id='depart-list'>"); $.each(depart.ferries, function(i, item) { console.log(item.result); }); $("#content").append("</ul>"); });
as can see i'm trying log results, come number of values attached key "ferries" undefined , i'm not sure why.
any appreciated.
edit
hey, tried using "item" supplied commenters
my each function follows:
$.each(depart.ferries, function(i,item) { $("#depart-list").append("<li class='depart-list-item'>" + item + "</li>"); });
here i'm trying populate list items, of course predictably returns bunch of list items content of "[object object]"
the html returns looks this:
<li class="depart-list-item">[object object]</li>
any further great!
try -
$.each(depart.ferries, function(i,v) { console.log(i + "," + v); });
Comments
Post a Comment