5Mi / wumi_blog

for recording improvimg my experience
21 stars 0 forks source link

JSON.stringify() 与JSON.parse() #38

Open 5Mi opened 8 years ago

5Mi commented 8 years ago

JSON.stringify()

将一个js对象 字符串化(将一个对象转化成json字符串);

var a = {a:1,b:2}

JSON.stringify(a)

//"{"a":1,"b":2}"

JSON.parse()

parse用于从一个字符串中解析出json对象

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

JSON.parse(str)

//Object
//age: "23"
//name: "huangxiaojian"
//__proto__: Object

注意:单引号写在{}外,每个属性名都必须用双引号,否则会抛出异常。