Home >Web Front-end >JS Tutorial >Introduction to the use of JSON.parse() and JSON.stringify()_javascript skills

Introduction to the use of JSON.parse() and JSON.stringify()_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:43:391275browse

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}"
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn