I get a JSON string by reference: https://app.heroku.com/vac/2 (link for example)
How can I parse JSON with javascript or jquery?
I get a JSON string by reference: https://app.heroku.com/vac/2 (link for example)
How can I parse JSON with javascript or jquery?
JSON.parse can be used to parse JSON strings .
JSON.parse('{}'); // {} JSON.parse('true'); // true JSON.parse('"foo"'); // "foo" JSON.parse('[1, 5, "false"]'); // [1, 5, "false"] JSON.parse('null'); // null When using the jQuery.getJSON function, jQuery.getJSON do not need to directly call JSON.parse , since it is already called internally.
Since jQuery.getJSON just a wrapper over a regular query, the result can also be obtained in the same way. For example, in the success handler
$.getJSON( "url", function( data ) { //data - javascript объект, результат обработки полученного json с помощью JSON.parse }); var a = jQuery.getJSON('https://app.heroku.com/vac/2'); var b = JSON.parse(a); alert( b.title ); var a = jQuery.getJSON('https://app.heroku.com/vac/2'); var b = JSON.parse(a); alert( b.title ); - VladParsit JSON.parse, but to avoid parsing errors, you need to intercept it or fly errors.
(url) => { let data; try { data = JSON.parse(url); // Парсим } catch(e) { data = null; // Перехватываем ошибку } if (data==null) return false; // Значит ошибка синтаксиса return data; // 100% валидный результат парсинга } Source: https://ru.stackoverflow.com/questions/510863/
All Articles
JSON.parse(data)? - BOPOH