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}