Im having trouble parsing a JSON string into a javascript object from a server, the code I got from this site, here is the code:
function bootstrap() {
var myObj;
var stringg;
var traerString = function(url) {
var xmlhttp = new XMLHttpRequest();
var res = null;
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
res = xmlhttp.responseText;
// console.log("resultado " + res);
xml2 = this.responseData;
return res;
}
};
xmlhttp.open("GET", url, false);
xmlhttp.send();
}
var convertiraObjeto = function(string) {
var sarasa = JSON.parse(string);
return sarasa;
}
stringg = traerString("https://fastspeedster.herokuapp.com/api/runners");
console.log(stringg);
myObj = JSON.parse(stringg);
for (var i=0;i<myObj.COLUMNS.length;i++)
{
var date = myObj.COLUMNS[i].runners;
console.log(date);
}
}
jQuery.Deferred exception: Unexpected token u in JSON at position 0 SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at HTMLDocument.bootstrap
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at HTMLDocument.bootstrap (demo.js:40)
at j (VM1318 jquery-3.1.1.min.js:2)
at k (VM1318 jquery-3.1.1.min.js:2)
I think the issue has to do with A-sync calls but im really a noob at this, all help is aprecciated