"SyntaxError: Unexpected end of JSON input", uniapp小程序URL传参包涵特殊字符
uniapp小程序中URL路径传参的时候包涵了特殊字符,我就遇到数据中包涵 = 号,url自动将等号进行了编码了,拿到的就是经过url自动处理之后的了,都不是原数据了
uni.reLaunch({
url:'../addPayAccount/addPayAccount?itm='+ (JSON.stringify(itm))
})
解决方法: URL参数一定要经过编码,使用encodeURIComponent进行编码
uni.reLaunch({
url:'../addPayAccount/addPayAccount?itm='+ encodeURIComponent(JSON.stringify(itm))
})
在接收的页面一定要使用decodeURIComponent进行解码
onLoad: function (e) {
if (e.itm) {
let data1 = JSON.parse(decodeURIComponent(e.itm))
}