I'm currently working on storing video information using JSON. I've managed to successfully read the JSON file, but I'm facing some challenges when trying to access the properties of the object. Specifically, I'm struggling with accessing the "fastvideos" array as obj.fastvideos[x]
is returning undefined even though the array is loaded as an object.
Could this issue be related to my JSON structure, or am I making a mistake in how I'm attempting to access the object?
JSON
{
"fastvideos": [{
"video-title": "sampletitle",
"video-tags": "tag1, tag2, tag3",
"video-desc": "sample-desc",
"video-url": "https://www.youtube.com/watch?v=<redacted>"
}, {
"video-title": "sampletitle2",
"video-tags": "tag1, tag2, tag3",
"video-desc": "sample-desc-2",
"video-url": "https://www.youtube.com/watch?v=<redacted>"
}]
}
JS
var obj = $.getJSON("videolist.json", function(json){
console.log(json);
});
document.getElementById("demo").innerHTML =
obj.fastvideos[1].video-title + ": URL = " + obj.fastvideos[1].video-url;