Created
April 23, 2016 20:00
-
-
Save joechan3/b129052ed9769432dc52ec861b919445 to your computer and use it in GitHub Desktop.
Using jQuery to parse JSON feeds From: Lynda - JavaScript and JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"full_name" : "Ray Villalobos", | |
"title" : "Staff Author", | |
"links" : [ | |
{ "blog" : "http://iviewsource.com" }, | |
{ "facebook" : "http://facebook.com/iviewsource" }, | |
{ "podcast" : "http://feeds.feedburner.com/authoredcontent" }, | |
{ "twitter" : "http://twitter.com/planetoftheweb" }, | |
{ "youtube" : "http://www.youtube.com/planetoftheweb" } | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>JavaScript And JSON</title> | |
</head> | |
<body> | |
<h2>Links</h2> | |
<ol id="links"> | |
</ol> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script src="myscript.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$.getJSON('data.json', function(info){ | |
var output=''; | |
for (var i = 0; i <= info.links.length-1; i++) { | |
for (key in info.links[i]) { | |
if (info.links[i].hasOwnProperty(key)) { | |
output += '<li>' + | |
'<a href = "' + info.links[i][key] + | |
'">' + key + '</a>'; | |
'</li>'; | |
} | |
} | |
} | |
var update = document.getElementById('links'); | |
update.innerHTML = output; | |
}); //getJSON | |
}); // ready |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment