javascript - Problems retrieving nested data from json -
i working on small project , made following json data -> http://www.smartbustracking.be/json/data.json.
the following below code loops through json data. can read "busuur" not nesting of bussen.
am writing code wrong of syntax not correct
<script type="text/javascript" language="javascript"> $.getjson("http://www.smartbustracking.be/json/data.json", function(json){ //$each same loop $.each(json, function(i, field) { $("#bussen").append("<li><a href='javascript: world.onpoidetailmorebuttonclicked();'>" + field.busuur + " " + field.bussen.busnummer + ": " + field.bussen.busnaam + "</><li><br />"); }); }); </script>
bussen
array
"bussen":[{"busnummer":"530","busnaam":"test bus 1"},{"busnummer":"540","busnaam":"mechelen"}]
you need iterate through items
for example , first item you'd :
$.each(json, function(i, field) { $("#bussen").append("<li>..." + field.bussen[0].busnummer + ": " + field.bussen[0].busnaam + "</><li><br />"); });
you might(!) want this :
$.each(json, function(i, field) { var a="<li><a href='javascript: world.onpoidetailmorebuttonclicked();'>" + field.busuur + " " ; var b=''; (var k=0;k<field.bussen.length;k++) b+= field.bussen[k].busnummer + ": " +field.bussen[k].busnaam ; console.log(a+b+ "</><li><br />"); });
Comments
Post a Comment