JS JSON数组与字符串的相互转换 JSON.parse()与JSON.stringify()

  public todos: {
    id: number,
    title: string,
    done: boolean
  }[] = JSON.parse(window.localStorage.getItem('todos') || '[]')

  ngDoCheck(){
    window.localStorage.setItem('todos', JSON.stringify(this.todos))
  }
  • JSON.parse() 将字符串转化为JSON数组

  • JSON.stringify() 将JSON数组转化为字符串

posted @ 2020-10-02 12:03  wing1377  阅读(385)  评论(0编辑  收藏  举报