• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

微信小程序生成二维码之传参(接收的参数乱码该咋解决)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

先说我的案例,我需要的是,扫码进入不同的区域展示(因此这个就需要进行二维码路径传参),大致思路:接收数据,然后根据所接收的数据进行判断,展示不同的区域。

我是用的草料二维码生成的 - https://cli.im/weapp

路径是这样的:pages/addPage/addPage?location=阿里爸爸

在我通过生成的二维码进入的时候发现,我得到的参数,是被微信小程序转译后的(\u963f\u91cc\u7238\u7238)不是我所需要的内容。转译地址:http://www.jsons.cn/unicode/

因此,我们就需要转译,通过所接收的参数进行转译然后得到正确的字符(阿里爸爸)

下串代码只做接收并进行转译操作

onLoad(option){
    this.currentLocation = option.location;
    //默认如果没有传输地址就为嘻嘻
    if (!this.currentLocation || this.currentLocation === undefined || this.currentLocation.trim() === \'\') {
        this.currentLocation = \'嘻嘻\';
    } else if (this.currentLocation.indexOf(\'\\u\') != -1) {
        // UNICODE转中文
        this.currentLocation = unescape(this.currentLocation.replace(/\\u/g, \'%u\'));
    } else if (this.currentLocation.indexOf(\'%\') != -1) {
        // encodeURI 转中文
        this.currentLocation = decodeURI(this.currentLocation);
    }
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap