var data1 = wx.getStorageSync('data') //本地json
var strdata = JSON.stringify(data1)
var objdata = JSON.parse(strdata)
console.log(strdata)
console.log(objdata )
本地的转换没问题,从数据库取出的utf-8编码字符串,转换时出现错误
var data2 = JSON.parse(res.data.data) //这里报错
下图90行和91行是本地json转换的,93是数据库返回的
后台返回的json字符串
{"listdata":[{"name":"邮箱","describe":"存放邮箱账号密码","rank":"2","creattime":1611809345023,"data":[]},{"name":"游戏","describe":"存放游戏账号","rank":"1","creattime":1611809345023,"data":[]},{"name":"网页","describe":"存放游戏账号","rank":"1","creattime":1611809345023,"data":[]},{"name":"其它","describe":"存放暂未分类的账号","rank":"0","creattime":1611809345023,"data":[]}],"openid":"null","recovery":[]}
找到原因了,因为存入后台是加密的,解密返回的时候生成了多余空白字符
wx.request 返回的时候转过一次了