原因
JSON.parse無法識別某些url中的特殊字符,所以報錯
mistakes.js中
nextBtn:function(){
var nextData = this.data.dataNextInfo;
console.log(nextData.pop());
var nextDatas = JSON.stringify(nextData.pop())
wx.redirectTo({
url: '../mistakes1/mistakes1?nextDatas=' + encodeURIComponent(nextDatas)
})
跳轉頁:mistakes1.js
/**
* 生命周期函數--監聽頁面加載
*/
onLoad: function (options) {
var nextData = decodeURIComponent((options.nextDatas));
console.log(JSON.parse(nextData));
},
解決方案
在JSON.stringify()之后將變量使用encodeURIComponent函數處理,encodeURIComponent() 函數可把字符串作為 URI 組件進行編碼。在目標頁面接收時用decodeURIComponent對URI 組件進行解碼,后通過JSON.parse()將變量還原。