Unexpected token u in JSON at position 0 解决

使用

localStorage

或者

sessionStorage

存入本地数据时,

存入了一个值为 Undefined ,当我在去取出来转换为JSON对象的时候,就是出现 Unexpected token u in JSON at position 0 报错

所以,当你存入数据和使用JSON.parse转换时需要判断一下,这个值不能为Undefined,才能进行JSON.parse

猜你喜欢

转载自blog.csdn.net/qq_37304462/article/details/111055865