美文网首页微信小程序
小程序wx.parse解析字符串报错

小程序wx.parse解析字符串报错

作者: Luv_coco | 来源:发表于2019-06-12 20:05 被阅读0次

页面跳转参数传递先用JSON.stringify()处理对象,然后URL编码

//点击卡片跳转详情
navigateToDetail(e){
    //输出当前卡片自定义的data-list数据
    // console.log(e.currentTarget.dataset.list)
    var str = encodeURIComponent( JSON.stringify(e.currentTarget.dataset.list) )
    wx.navigateTo({
      url: '/pages/detail/detail?json=' + str
    })
},

接收参数页面,URL解码之后,再JSON.parse()

onLoad: function (options) {
    //获取卡片传来的数据
    var pageData = JSON.parse(decodeURIComponent(options.json))
}

一般情况不用URL编码、解码操作,遇到要传递的对象参数有特殊字符(? / <> )等,需要套一层encodeURIComponent解决。

相关文章

网友评论

    本文标题:小程序wx.parse解析字符串报错

    本文链接:https://www.haomeiwen.com/subject/fuurfctx.html