How eval functions work
The eval function evaluates a given string containing javascript code, and the view executes the expressions or
A series of legal javascript statements. The eval function uses the value or reference contained in the last expression or statement as the return value.
console.info(eval("alert('a');alert('b')"))console.info(eval("x=10;y=20;alert(x*y)")); //200console.info(eval("3+6")); //9
JSON format
Json is simply an object and an array in javascript. Therefore, the two structures are objects and arrays. These two structures can represent various complex structures.
1. Object: Content enclosed by the object represented as "{}" in js. The data structure is {key: value, key: value ,...} the structure of the key-value pair. In the object-oriented language, the key is the object attribute, and the value is the corresponding attribute value, so it is easy to understand. The value method is the object. key, which can be a number, String, array, or object.
2. array: The array is enclosed by brackets "[]" in js. The data structure is ["java", "javascript", "vb",...], the value can be obtained using indexes in the same way as in all languages. Field values can be of the following types: Numbers, strings, arrays, and objects.
After the object and array structures, you can combine them into complex data structures.
{"AcceptIs": null, "entity": null, "refuseIs": null, "result": {"pageSize": 10, "resultList": [{"SHNOTE ": "Ferrari F40", "STATE": "Submit", "CTIME": "13:53:28", "PHONE": "13111050937", "ID ": "40288ba54000028000014000036c6c60000",},], "totalPage": 1, "totalSize": 4 }}
Eval and JSON
The eval function can be used to convert JSON data into available javascript objects.
var datas=eval("("+data+")");
Why should we add parentheses?
The purpose of parentheses is to enable the eval function to forcibly convert the expressions in parentheses into objects when evaluating javascript code,
Instead of being executed as a statement. For example, if the object {} does not contain outer brackets, eval identifies the braces as the start and end marks of the javascript code block, then {} is considered to have executed an empty statement. As follows:
console.info(eval("{}")); //undefined console.info(eval("({})")); //Object {}
Project Code involved:
$(document).ready(function(){$.post('/homea/admin/UserBookView.do', {}, function(data) { var datas=eval("("+data+")");for(var i=0;i