What is JSON? JSON is full of JavaScript object Notation (JavaScript Object notation), which is based on the literal of JavaScript objects, and if you look at it from the eyes, the data in the JSON is stored in curly braces-{}, If further analysis is used, JSON is a data interchange format. The JSON interior is arranged in the form of a name: value, such as the following Json1, which is a JSON object.
var json2={"name": "Zhang San", "age": +, "Sex": "Boy"}
What is a JSON string? In the literal sense, add double quotation marks (or single quotation marks) around the JSON, and to avoid the internal double quotes, we put the single quotation mark outside, which is a JSON string, as in the following Json2
var json2= ' {' name ': ' Zhang San ', ' age ': +, ' sex ': ' Boy '} '
Method One: Use the Eval method to parse a JSON string into a JSON objectThere are no compatibility issues with EVEL, but there are security vulnerabilities. Method Two: Use the Json.parse method to refer to JSON string parsing as a JSON objectJson.parse There is no security vulnerability, but there is compatibility, IE8 and not supported. :
Run results
//create an object XMLHttpRequest varajax=NewXMLHttpRequest (); //Create an HTTP request, set the request addressAjax.open ("Get", "testservlet.do"); //Send request (get is null post as parameter)Ajax.send (NULL); //set an event for Ajax (most 4[1-4 in this sense)Ajax.onreadystatechange =function(){ //5. Get the response //ResponseText receive the information returned by the server as a string //Console.log (ajax.readystate); if(Ajax.readystate = = 4 && ajax.status = 200){ //use the Json.parse method to refer to JSON string parsing as a JSON object vardata =Json.parse (Ajax.responsetext); Console.log (Data.data); //Use the Eval method to parse a JSON string into a JSON object varData1=eval ("(" +ajax.responsetext+ ")"); Console.log (Data1.data); } }
Native Ajax receives JSON string (simple Introduction)