当前位置:网站首页>解决报错SyntaxError:Unexpected end of JSON input
解决报错SyntaxError:Unexpected end of JSON input
2022-07-19 14:00:00 【xuefankang】
跳转页面传递参数
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格式的对象/数组。
修改如下:
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;
},
边栏推荐
- [introduction series of redis] get to know redis and the installation of redis
- 测试--基础知识篇
- 基于领域本体的科技资源聚类方法研究
- 上半年广东出口增长7.3%,高新技术产品加快“出海”
- Taishan Office Technology Lecture: Taking A4 as an example, what is the page structure
- 解决npm错误Error: Cannot find module ‘shelljs‘
- 行业现状令人失望,工作之后我又回到UC伯克利读博了
- Understand chisel language thoroughly 18. Detailed explanation of chisel module (V) -- Verilog module used in chisel
- 钢格栅板是什么?
- atos比例溢流阀AGMZO-TERS-PS-010/315
猜你喜欢
硅谷课堂第十一课-公众号消息和微信授权
“还是太年轻”,实习生花2分钟解决bug,老程序员的反应耐人寻味
力士乐比例节流阀2WRCE80D001-1X/PG24/M-120
2022-7-14 Jmeter模拟不同用户登录进行压测
【性能优化】MySQL性能优化之存储引擎调优
Silicon Valley class lesson 14 - Live docking and wechat sharing
Microsoft Edge浏览器怎么设置主页
深入了解JUC并发(八)线程池
Deep understanding of JUC concurrency (IX) deep understanding of CAS
Development of video splicing technology
随机推荐
显式动力学子模型法在航空发动机整机瞬态冲击并行计算中的应用
矽穀課堂第十三課-直播管理模塊
软考 系统架构设计师 简明教程 | 软件生命周期
"Still too young", the intern spent 2 minutes to solve the bug, and the old programmer's response was intriguing
使用 GPU 发现人脑连接,大规模 GPU 实现了 100 倍的加速
UVM in UVM_ Usage with parameters in event
泰山OFFICE技术讲座:以A4为例,页面结构是怎样的
【一起学Rust】Rust包管理工具Cargo初步了解
Plunger pump Parker pvp23363r26a121
数据库高并发下怎么避免重复数据产生
2022-7-14 Jmeter进行压测
Emeditor based corpus statistics and analysis
吃透Chisel语言.17.Chisel模块详解(四)——用函数实现轻量级模块
吃透Chisel语言.15.Chisel模块详解(二)——Chisel模块嵌套和ALU实现
如何打造3D立体世界?跟随图片一同探寻
飞凌OK1028A核心板适配RTL8192CU WIFI模块
解决npm错误Error: Cannot find module ‘shelljs‘
【性能优化】MySQL性能优化之存储引擎调优
备赛笔记:Opencv学习:颜色识别
Huggingface | BLOOM模型训练背后的技术