parse用于从一个字符串中解析出json对象,如
var str = '{"name":"huangxiaojian","age":"23"}'
结果:
JSON.parse(str)
Object
age: "23"
name: "huangxiaojian"
__proto__: Object
注意:单引号写在{}外,每个属性名都必须用双引号,否则会抛出异常。
stringify()用于从一个对象解析出字符串,如
结果:
JSON.stringify(a)
"{"a":1,"b":2}"
[b]PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:[/b]
在线JSON代码检验、检验、美化、格式化工具:
[url=http://tools.jb51.net/code/json]http://tools.jb51.net/code/json[/url]
JSON在线格式化工具:
[url=http://tools.jb51.net/code/jsonformat]http://tools.jb51.net/code/jsonformat[/url]
在线XML/JSON互相转换工具:
[url=http://tools.jb51.net/code/xmljson]http://tools.jb51.net/code/xmljson[/url]
json代码在线格式化/美化/压缩/编辑/转换工具:
[url=http://tools.jb51.net/code/jsoncodeformat]http://tools.jb51.net/code/jsoncodeformat[/url]
在线json压缩/转义工具:
[url=http://tools.jb51.net/code/json_yasuo_trans]http://tools.jb51.net/code/json_yasuo_trans[/url]
C语言风格/HTML/CSS/json代码格式化美化工具:
[url=http://tools.jb51.net/code/ccode_html_css_json]http://tools.jb51.net/code/ccode_html_css_json[/url]