.net 长时间没有操作页面,导致localStorage消失,一些页面用到localStorage的需要json反序列化,但是json不能序列化为undefined的,求解

.net 长时间没有操作页面 导致了localStorage消失,然后一些用到localStorage的页面,因为localStorage里的内容消失了,是undefined,而在使用localStorage之前要json序列化一下,才能用里面的数据,而json是不能序列化undefined,使用页面会报错,这么解决呢?

//先判断数据是否为undefined,再去序列化
iftypeof(info) !== 'undefined'const jsonText = JSON.stringify(info)