Simply record the use of the Json.parse () and json.stringify () functions in jquery, and the eval () function in JS
1,json.parse function (Common)
Function: Converts a JavaScript object notation (JSON) string to an object.
Grammar:JSON.parse(text [
reviver])
Parameters:
- text required. a valid JSON string.
- Reviver Optional. a function that transforms the result. This function is called for each member of the object.
Return value: An object or an array
Example:
var json = ' {' name ': ' YZ ', ' age ': ' University ': ' Sjzxy '} '; var info = json.parse (JSON); Resolves to a JSON object document.write (Info.name + ' is a student of ' + info. University + ' and he is ' + Info.age + "Years"); /info to Object
2,json.stringify () function
Role: Converts JavaScript values to JavaScript Object Notation (JSON) strings
Syntax: json.stringify (value [, Replacer] [, space])
Parameters:
- Value required, typically a JavaScript value (usually an object or an array) that needs to be converted
- Replacer optional, function or array for converting results
- Space is optional. adds indents, spaces, and line breaks to the return value JSON text to make it easier to read.
Return value: A string containing JSON text
Example
var info = {Name: "YZ", age:22,university: "Sjzxy"}; var json = json.stringify (info); Convert to JSON string
document.write (JSON); Output is {"name": "GDT", "Age": "University": "Gdut"}
(3) eval () function
Function: the eval () function computes a string and executes the JavaScript code in it.
Syntax:eval (String)
Parameters:
- String required to be evaluated, containing the JAVASCRIPT expression to be evaluated or the statement to be executed.
Return value: Returns the value of the computed string, if any (no change is returned)
Example
Eval ("X=11;y=2;document.write (X*y)"); Output is document.write (eval ("+ +)"); Output is 4 var x=10; document.write (eval (x+17)); Output is 27
The format of the eval () parsing string
Alert (eval (' (' + ' (' + ') ' {} ') ') but Eval () is unsafe for easy execution of dangerous code inside
Example:
var str2 = ' {' A ': (function () {alert ("I can do something bad!");}) ()}‘;
Eval (' (' +str2+ ') ');
The code that executes the danger is unsafe but json.parse () completely overcomes this problem, so the actual use of less
--Citation of Internet information if infringement is deleted
JSON-Common conversions