I am working with learning json right now and to get my feat wet so to speak I was wondering what would be the best way to get a file with json info and populate a site with it. The file would be something like this:
window.test =
{
"header1":
[
{ "title": "title1", "author": "author1"},
{ "title": "title2", "author": "author2"},
{ "title": "title3", "author": "author3"}
],
"header2":
[
{ "title": "title1", "author": "author1"},
{ "title": "title1", "author": "author2"},
{ "title": "title1", "author": "author3"}
]
};
Then would the code be something like this?
$(function() {
$.getJSON('jsonFile.js',function(data){
$.each(data, function(){
console.log(header1.title);
console.log(header2.title);
});
});
});
Again I am a newbie with JSON so any tutorials, suggestions, well anything to help me understand core concepts here would help.
Your json:
Your code:
Optionally, do a each() over data.header1 and data.header2