Home >Backend Development >PHP Tutorial >javascript - After scanning the barcode with WeChat, how do you parse the result?
<code>wx.scanQRCode({ needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有 success: function (res) { var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果 } });</code>
How to parse the obtained result?
<code>wx.scanQRCode({ needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有 success: function (res) { var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果 } });</code>
How to parse the obtained result?
<code> var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果</code>
Use WeChat’s debugger and console.log() to print the result numerical analysis
What do you mean by your question?
I don’t understand. Isn't result the result of scanning?
You can use the string method to get what you want,
or ajax and pass it to the backend
or window.location.href = result
You can achieve page jump
First of all, what type is your res
data? If it is in json
format, use JSON.parse
to convert it into an object and continue the operation.
<code>success: function (res) { var result = JSON.parse(res); //这里把json类型的res转换成对象 if(result.needResult == 1) { alert('nice!'); } }</code>