1、对象转字符串

const obj = {
     id: 0,
     name: '张三',
     age: 12
}
const objToStr = JSON.stringify(obj)
console.log('obj:', obj)
console.log('objToStr:', objToStr)

JS对象与字符串的相互转换

 2、json字符串转对象

const str = '{"id":0,"name":"张三","age":12}'
const strToObj = JSON.parse(str)
console.log('str:', str)
console.log('strToObj:', strToObj)

JS对象与字符串的相互转换

 转载https://www.cnblogs.com/susu8/p/9173913.html

相关文章:

  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-11-30
  • 2022-02-07
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-02-07
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案