JSON.parse()

Total Post:113

Points:791
JSON 
 172  View(s)
Ratings:
Rate this:

how to use JSON.parse().

  1. Post:140

    Points:984
    Re: JSON.parse()

    JSON.parse() :

    common use of JSON is exchange data from a web server.it's in form of string data type. 

    syntax: 

    var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
    

    Ex : JSON from the server. 

    var xmlhttp = new XMLHttpRequest(); 
    xmlhttp.onreadystatechange = function() {
        if(this.readyState == 2 && this.status == 100){
            var myObj = JSON.parse(this.responseText);
            document.getElementById("demo").innerHTML = myObj.name;
        }
    };
    xmlhttp.open("GET", "json_demo.txt", true);
    xmlhttp.send();


Answer