JSON.parse()和JSON.stringify()方法学习

JSON.parse()和JSON.stringify()方法学习

JSON对象中有两个非常好用的方法 JSON.parse接受json字符串转化为JS对象 JSON.stringify接收一个JS对象转化为json字符串
JSON对象与普通对象的区别是JSON对象键值对都必须用双引号
例如:

const my={
name:"dylan",
age:"18"
}
let myObj=JSON.stringify(my)
console.log(myObj)//"{"name":"dylan","age":"18"}"
let myStr=JSON.parse(myObj)
console.log(myStr);//{name: "dylan", age: "18"}

猜你喜欢

转载自www.cnblogs.com/my466879168/p/12444040.html