parsing methods for JSON (non-original)
There are two ways to parse JSON: Eval_r () and Json.parse (), using the following methods:
var jsondata = ' {' data1 ': ' Hello, ', ' data2 ': ' world!} ';
var evaljson=eval_r (' (' +jsondata+ ') ');
var jsonparsejson=json.parse (Jsondata);
This converts the Jsondata JSON-formatted string into a JSON object.
The differences are as follows:
var value = 1;
var jsonstr = ' {' data1 ': "Hello", "data2": ++value} ';
var data1 = Eval_r (' (' +jsonstr+ ') '); Console.log (data1);//This value is 2vardata2=json.parse (JSONSTR); Console.log (data2 );//Error
You can see the results of the control output, the first eval_r () successfully executed, the second error.
As can be seen from the above example, eval will execute the code in the string when parsing the string (the consequences are pretty bad), as in the previous example, the value of the original values has been changed by using Eval to parse a JSON string.
The difference between Eval and parse in JSON