Home > Article > Web Front-end > Use eval to generate JSON objects under js_javascript skills
For example: var json = eval('(' ret ')');
Suppose we use PHP's encode_json() on the server side to generate the string that needs to be returned
If the generated string is [{"name" :"boke"},{"age":"23"}],
We can directly use eval([{"name":"boke"},{"age":"23"}]) to generate the corresponding JSON object;
If the generated string is {"name":"boke","age":"23"},
We use eval({"name":"boke","age" :"23"}) An error will occur when generating a JSON object
, we need to write eval(({"name":"boke","age":"23"})) like this.
The writing method of eval(( )) is also applicable to other strings generated by the encode_json() function, including the first case.
You can also use a special