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数组转化为字符串

浙公网安备 33010602011771号