Thanks to the advent of Ajax, the lightweight data format of JSON is becoming increasingly popular as a transport format between client and server, and the problem is how to translate the server-side JSON data into usable JavaScript objects. Using the Eval function is undoubtedly a simple and straightforward approach. You need to wrap a layer of parentheses around the outside of the JSON string when converting:
var=eval("("++")");
Why do you want to add parentheses?
The purpose of the parentheses is to force the Eval function to force the expression in parentheses to be converted to an object while processing the JavaScript code, rather than being executed as a statement (statement). For example, if the object literal {} is not enclosed, then eval will recognize the curly brace as the start and end tag of the JavaScript block, and {} will be considered an empty statement. So the following two execution results are different:
Alert(eval("{}"); Return undefinedalert(eval("({})"); return Object[object]
JS in eval processing JSON data why parentheses