自定义一个对象info,里面存Json对象
window.localStorage.info =JSON.stringify({
userName:'aa'
})
取出时,先转化为JSON,再从中取值
var info = JSON.parse(localStorage.getItem('info'))
var username = info.userName ;
console.log("username:"+username);
效果