userName: JSON.stringify(wx.getStorageSync('userInfo').userName),
得到的数据解析后带双引号,
这真是一个气吐血的坑。
需要在往storage种存储的时候使用
wx.setStorageSync('userInfo',JSON.parse(userInfo))
再解析
userName: wx.getStorageSync('userInfo').userName,
就能得到正常的数据了
本文介绍了一个关于微信小程序中使用wxStorage存储和读取数据时遇到的问题:读取到的数据带有双引号,导致数据解析错误。通过正确的使用JSON.parse和JSON.stringify方法,可以在存储时去除双引号,确保数据的正确读取。
userName: JSON.stringify(wx.getStorageSync('userInfo').userName),
得到的数据解析后带双引号,
这真是一个气吐血的坑。
需要在往storage种存储的时候使用
wx.setStorageSync('userInfo',JSON.parse(userInfo))
再解析
userName: wx.getStorageSync('userInfo').userName,
就能得到正常的数据了

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