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

posted @ 2020-06-03 15:33  龙卷风吹毁停车场  阅读(61914)  评论(0编辑  收藏  举报