小程序路由传参,参数转换报错:SyntaxError: Unexpected end of JSON input
原因:小程序路由传参对参数长度有限制,当传递的参数超出限制时,会被截取。
//item为要传递的对象
wx.navigateTo({
url: '/XX?item=' + JSON.stringify(item)
})
onLoad(options){
//options是接收的item参数 ,此时的item参数由于长度超出限度,已经被截取
console.log(options)
let item = JSON.parse(options.item)
//此时就会报错:SyntaxError: Unexpected end of JSON input
}