Working on the quote generator here with the remotely stored JSON quotes here.
My function to pull the data is:
function getQuotes(){
return $.getJSON('https://raw.githubusercontent.com/themagicbean/bojackquotejson/master/bojackquotes')
.done(function(retrievedData) {
console.log(retrievedData);
let quotesData = retrievedData;
console.log('got data');
let quotes = retrievedData.quotes;
console.log(quotes);
console.log("extracted the array of quotes");
//from here not working
let parsedQuotes = JSON.parse(quotes);
console.log(quotesData);
console.log("extracted the quote objects from the array")
}).fail(function(error) {
// Something wrong happened. Like GOT Season 8.
console.error('We could not fetch or parse the data:', error);
});
}
I get the object, and the array of quotes. The console logs “extracted the array of quotes” but stops there.
If I remove the array extraction step, so the code is like so:
function getQuotes(){
return $.getJSON('https://raw.githubusercontent.com/themagicbean/bojackquotejson/master/bojackquotes')
.done(function(retrievedData) {
console.log(retrievedData);
let quotesData = retrievedData;
console.log('got data');
/*
let quotes = retrievedData.quotes;
console.log(quotes);
console.log("extracted the array of quotes");
//from here not working
*/
let parsedQuotes = JSON.parse(retrievedData);
console.log(quotesData);
console.log("extracted the quote objects from the array")
}).fail(function(error) {
// Something wrong happened. Like GOT Season 8.
console.error('We could not fetch or parse the data:', error);
});
}
Then it similarly gets the data, but does not parse.
How do I parse the object? Thanks!