Method 1: The most famous eval method in js
var strJson="{name:'Zhang San'}";//json
var obj=eval("(" strJson ")");//Converted json object
alert(obj.name);//json name
Things to note about this method are:
The object expression {'name':'Zhang San'} must be expanded with "()", otherwise
var strJSON = "{name:'Zhang San'}";
var obj = eval(strJSON);
alert(obj.constructor);//String constructor
alert(obj.name);//undefine
The object expression must be expanded and eval executed to generate an anonymous object!
Method 2: Function construction definition method returns
var strJSON = "{name:'Zhang San'}";//The obtained JSON
var obj = new Function("return" strJSON)();//Converted JSON object
alert(obj.name);//json name