uniapp开发微信小程序中出现错误:Error in onLoad hook: “SyntaxError: Unexpected end of JSON in

332 阅读1分钟

25.png

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

解决办法:
页面A(JSON.stringify传参)

    messageInfo(item) {
                uni.navigateTo({
                    url: `/pagesA/pages/message/chat?info=${encodeURIComponent(JSON.stringify(item))}&type=2`
                    
                    // 或者                    
                    url:'/pages/order/userPay?options='+ encodeURIComponent(JSON.stringify(options))
    },

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

接收页面

    onLoad(option) {
            let info = JSON.parse(decodeURIComponent(option.info))
    }

原文链接:blog.csdn.net/weixin_4632…