There is a json file:
{ "list": [ {"country": "USA", "region": "North America", "population": 321368000000}, {"country": "Russia", "region": "Europe/Asia", "population": 146880432}, ] } There is such code:
var xhr = new XMLHttpRequest(); xhr.open("GET", 'list.json', true); xhr.send(); xhr.onreadystatechange = function() { if(xhr.readyState ===4) { document.getElementsByClassName('country')[0].innerHTML = xhr.responseText }; if(xhr.status !=200) { console.log(xhr.status + ": " + xhr.statusText); }; }
How do I transfer in html separate json value? I know that I need to use json.parse, but I don’t understand why.
json.parse(xhr.responseText).list[0].country == USA,json.parse(xhr.responseText).list[1].country == Russia- Vladimir Klykov