Answer the question
In order to leave comments, you need to log in
JSON parsing error - SyntaxError: unexpected token: numeric literal. What to do?
There is api https://api.bybit.com/v2/public/tickers , I'm trying to get the price of bitcoin from it result.0.last_price It doesn't work, browsers swear at 0 (zero) in the request. Here is the function code:
function GetBybitPrice() {
let zapros = new XMLHttpRequest();
zapros.open('GET', ' https://api.bybit.com/v2/public/tickers ');
zapros.onreadystatechange = function () {
if (this.readyState === 4) {
let answer = JSON.parse(zapros.responseText);
document.getElementById("bybit").innerText = response.result.0.last_price;
}
};
request.send();
}
Browsers don't digest otvet.result.0.last_price; because there is 0 in the string.
Firefox writes an error: SyntaxError: unexpected token: numeric literal
Chrome: Uncaught SyntaxError: Unexpected number
How to get to last_price then?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question