跳转页面传递参数
var selectWorker = JSON.stringify(selectWorker);
uni.navigateTo({
url: '../recordForm/recordForm?selectWorker=' + selectWorker
})
onLoad(option) {
console.log(option)
var _this = this;
// 选中的工人
var selectWorker = JSON.parse(option.selectWorker);
var workerIdsArray = [];
for (var i = 0; i < selectWorker.length; i++) {
workerIdsArray.push(selectWorker[i].id);
}
var workerIds = workerIdsArray.join(',');
console.log(workerIds);
_this.selectWorker = selectWorker;
_this.workerIds = workerIds;
},
报错提示
SyntaxError:Unexpected end of JSON input
解决方案
原因:若对象的参数或数组的元素中遇到地址中包括?& - _ . ! ~ * ' ( )等特殊符号时,对象/数组先要通过JSON.stringify转化为字符串再通过encodeURIComponent编码,接收时,先通过decodeURIComponent解码再通过JSON.parse转换为JSON格式的对象/数组。文章来源:https://www.toymoban.com/news/detail-678708.html
修改如下:文章来源地址https://www.toymoban.com/news/detail-678708.html
var selectWorker = JSON.stringify(selectWorker);
uni.navigateTo({
url: '../recordForm/recordForm?selectWorker=' + encodeURIComponent(selectWorker)
})
onLoad(option) {
console.log(option)
var _this = this;
// 选中的工人
var selectWorker = JSON.parse(decodeURIComponent(option.selectWorker));
var workerIdsArray = [];
for (var i = 0; i < selectWorker.length; i++) {
workerIdsArray.push(selectWorker[i].id);
}
var workerIds = workerIdsArray.join(',');
console.log(workerIds);
_this.selectWorker = selectWorker;
_this.workerIds = workerIds;
},
到了这里,关于解决报错SyntaxError:Unexpected end of JSON input的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!