Currently, I am attempting to parse JSON data that is being returned by The Movie DB. Unfortunately, I keep encountering an error message indicating the following:
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at XMLHttpRequest.movieReq.onreadystatechange (discover.js:34)
at loadIMDBDetails (discover.js:38)
at MainFunc (discover.js:68)
at discover.js:5
The issue arises when I try to access individual movie information through this XMLHttpRequest:
movieReq.open('GET', '', false);
I have other XMLHttpRequests which successfully retrieve JSON data without any problems. These requests utilize the discover function of the API.
Below is the function causing the problem:
function loadIMDBDetails(mO, i) {
movieReq = new XMLHttpRequest();
movieReq.onreadystatechange = function () {
var parsedObj = JSON.parse(movieReq.responseText);
mO.imdbId = parsedObj['imdb_id'];
};
movieReq.open('GET', 'https://api.themoviedb.org/3/movie/299537?api_key=34f8307d9addabf7924eab7f22cabb23', false);
movieReq.send();
}
When utilizing console.log to display the responseText, the output is as follows:
{"adult":false,"backdrop_path":"/w2PMyoyLU22YvrGK3smVM9fW1jj.jpg","belongs_to_collection":null,"budget":152000000,"genres":[{"id":28,"name":"Action"},{"id":12,"name":"Adventure"},{"id":878,"name":"Science Fiction"}],"homepage":"",...}