Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:43:39
Original
1247 people have browsed it

parse is used to parse a json object from a string, such as

var str = '{"name":"huangxiaojian","age":"23"}'
Copy after login

Result:

JSON.parse(str)

Object

age: "23"
name: "huangxiaojian"
__proto__: Object
Copy after login

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}
Copy after login

Result:

JSON.stringify(a)

"{"a":1,"b":2}"
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!