I am trying to output the results of a data.json file, but I keep getting the wrong output. at first I was getting [obj obj], but I tried this method, and it seems to be getting the index.
I even removed the outside curly braces and the games title from the JSON file, but still not working. At the moment, I am just trying to console the game title, but the idea is to output the whole thing.
//my JSON is in a different file
{
"games" : [
{
"gameImg" : "img/deathstranding.jpg",
"gameTitle" : "Death Stranding",
"gameInfo" : "some game info"
},
{
"gameImg" : "img/deathstranding.jpg",
"gameTitle" : "Death Stranding",
"gameInfo" : "some game info"
}
]
}
// JS
function init2() {
$.ajax({
url: "js/data.json",
type: "GET",
dataType: "json",
async: false,
success: function (data) {
JSON.stringify(data);
$.each(data, function( val ) {
var items = [];
items.push( "<li>" + val + "</li>" );
console.log('gameTittle:', items);
});
}
});
}
init2();