首先,localStorage中只能存储字符串
所以,存储对象数组,必须先转成字符串再存储
localStorage.pList=JSON.stringify([]);
需要时,再将localStorage中的字符串转成对象数组
var tmp_pList=JSON.parse(localStorage.pList);参考链接:
点击打开链接
本文介绍如何使用JSON.stringify()和JSON.parse()方法实现localStorage中对象数组的存储与读取。由于localStorage只支持字符串类型的数据存储,因此在保存复杂数据结构如对象数组时,需要先将其转换为字符串形式。
首先,localStorage中只能存储字符串
所以,存储对象数组,必须先转成字符串再存储
localStorage.pList=JSON.stringify([]);
需要时,再将localStorage中的字符串转成对象数组
var tmp_pList=JSON.parse(localStorage.pList);参考链接:
点击打开链接
8440
295
1856
2907

被折叠的 条评论
为什么被折叠?