前言
在使用生成二维码的wxacode.getUnlimited时候,传入scene中,参数不支持中文和特俗字符。如果我们需要传入一个对象,却是不行的,这很尴尬 如:{u:abc,w:123}
编码与解码
var str='{u:abc,w:123}'
str= encodeURIComponent(str)
console.log('encodeURIComponent',str);
str=decodeURIComponent(str);
console.log('encodeURIComponent',str)
效果

还有其它方式编码与解码,这里使用encodeURIComponent
大家可以去测试其它呢
综合应用
var json= {
u:'abc',
p:'123'
}
var str=JSON.stringify(json);
str= encodeURIComponent(str)
console.log('encodeURIComponent',str);
str=decodeURIComponent(str);
console.log('encodeURIComponent',str)
var data= JSON.parse(str);
console.log(data.u)
结果

本文探讨了在使用微信小程序生成无限数量二维码(wxacode.getUnlimited)时遇到的中文和特殊字符支持问题。通过示例展示了如何使用encodeURIComponent进行参数编码与解码,确保对象能正确传递。文章还提到了JSON.stringify和JSON.parse在处理复杂对象时的作用,并鼓励读者测试更多编码解码方法。


1万+

被折叠的 条评论
为什么被折叠?



