Here's some code I'm working with:
var default_links =
'{ "name" : "Google", "url": "https://encrypted.google.com/", "fav_url": "https://encrypted.google.com/favicon.ico" }\n'+
'{ "name" : "Yahoo", "url": "http://www.yahoo.com/", "fav_url": "http://www.yahoo.com/favicon.ico" }\n'+
'{ "name" : "GMail", "url": "https://mail.google.com/", "fav_url": "https://mail.google.com/favicon.ico" }\n'+
'{ "name" : "Twitter", "url": "https://www.twitter.com/", "fav_url": "https://www.twitter.com/favicon.ico" }\n'+
'{ "name" : "Facebook", "url": "https://www.facebook.com/", "fav_url": "https://www.facebook.com/favicon.ico" }\n'+
'{ "name" : "Wikipedia", "url": "https://en.wikipedia.org/", "fav_url": "http://en.wikipedia.com/favicon.ico" }\n';
function write_links()
{
var linkdata = default_links.split("\n");
for (i = 0; i < linkdata.length; i++)
{
var link = JSON.parse(linkdata[i]);
document.getElementById("useful_links").innerHTML += '<a href=\"' + link.url + '"><img src="' + link.fav_url + '">' + link.name + '</a><br>';
}
}
After parsing all the lines, an error shows up:
[xx:xx:xx.xxx] SyntaxError: JSON.parse: unexpected end of data @ http://127.0.0.1/homepage.html:33
What might be causing this issue?
(Yes, I know the design isn't great with splitting by \n
, but it's a temporary solution for specific undisclosed issues.)