前言
在使用生成二维码的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)
结果