h5嵌入鸿蒙跳转支付宝支付,报错:Syntax error:JSON Parse error:Expected ‘}‘
方法二:后台base64处理支付宝返回的payUrl字符串,前端再decode处理。方法一:JSON.parse之前将字符串特殊字符处理下。
·

h5嵌入鸿蒙,h5跳到支付宝沙箱版本支付页面时,JSON.parse又报错了,此处有2种解决方式:
方法一:JSON.parse之前将字符串特殊字符处理下
const responseString = responseStr.indexOf("payUrl") == -1 ? responseStr.replace(/\n/g, "\\n") :
responseStr.replace(/([{,]\s*"payUrl"\s*:\s*")(.*?)("\s*[,}])/gs, (match, prefix, content, suffix) => {
const escaped = content
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/\t/g, '\\t');
return `${prefix}${escaped}${suffix}`;
});
方法二:后台base64处理支付宝返回的payUrl字符串,前端再decode处理
![]()


更多推荐



所有评论(0)