JSON.parse()和JSON.stringify()
stringify()用于从一个对象解析出字符串;
var person = {name:"vanida","sex":"girl","age":25};
localStorage.setItem("person",JSON.stringify(person));
// localStorage.person="{"name":"vanida","sex":"girl","age":25}"
注意:JSON.stringify()中不要忘了“i”,stringify而不是stringfy!
parse用于从一个字符串中解析出json对象 可以用JSON.parse();
person = JSON.parse(localStorage.getItem("person"));
// {name: "vanida", sex: "girl", age: 25}
欢乐的时光如此短暂,好了,今天就到这里了,觉得不错麻烦点个赞,danielwu的前端之路有你相伴,咱们下期再见!