Home >Web Front-end >JS Tutorial >Introduction to the use of JSON.parse() and JSON.stringify()_javascript skills
parse is used to parse a json object from a string, such as
var str = '{"name":"huangxiaojian","age":"23"}'
Result:
JSON.parse(str) Object age: "23" name: "huangxiaojian" __proto__: Object
Note: Single quotation marks are written outside {}, and each attribute name must use double quotation marks, otherwise an exception will be thrown.
stringify() is used to parse a string from an object, such as
var a = {a:1,b:2}
Result:
JSON.stringify(a) "{"a":1,"b":2}"