uniapp 开发微信小程序出现这个 Error in onLoad hook: “SyntaxError: Unexpected end of JSON input“

 原因:这个其实是由于JSON.parse无法识别某些url中的特殊字符比如&等特殊符号造成的。

解决办法:

页面A(JSON.stringify传参)

 toactivity(item){
        uni.navigateTo({
          url:'/util_pages/apply-page?item='+encodeURIComponent(JSON.stringify(item))
        })
      },

页面B(JSON.parse接受参数)

接收页面

onLoad(option) {
	// 接收数据
	let str = decodeURIComponent(option.item)
	 this.activity = JSON.parse(str)
}

主要就是使用encodeURIComponent 和 decodeURIComponent

猜你喜欢

转载自blog.csdn.net/weixin_64103049/article/details/128458530