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.

  • 2
    For clarity, immediately what will happen where - json.parse(xhr.responseText).list[0].country == USA , json.parse(xhr.responseText).list[1].country == Russia - Vladimir Klykov
  • Something you have in the US population more than people were for the whole existence of mankind;) - Alexey Ten

0