JSON.stringify()和JSON.parse()

var obj = {
     name:'tom',
     age:22,
     data:{
           username:'admin',
           password:'admin'
     }
}
var str = JSON.stringify(obj)//将对象转化为JSON字符串
console.log(str)//{"name":"tom","age":22,"data":{"username":"admin","password":"admin"}}
var obj1 = JSON.parse(str)//将JSON字符串转为对象
console.log(obj1)//Object {name: "tom", age: 22, data: Object}

 

posted @ 2017-05-03 16:16  年少的你如此美丽  阅读(109)  评论(0编辑  收藏  举报