1. 对象转为字符串
const obj = { id: 0, name: '张三', age: 12 } const objToStr = JSON.stringify(obj) console.log('obj:', obj) console.log('objToStr:', objToStr)
2. json字符串转为对象
const str = '{"id":0,"name":"张三","age":12}' const strToObj = JSON.parse(str) console.log('str:', str) console.log('strToObj:', strToObj)