解决报错SyntaxError:Unexpected end of JSON input
跳转页面传递参数
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;
},
解决报错SyntaxError:Unexpected end of JSON input相关推荐
- golang使用josn.Unmarshal报错:unexpected end of JSON input
在go语言中使用Unmarshal()解析来自HTTP响应的JSON数据报错:unexpected end of JSON input问题一般是分为以下情况: 当我们在通过http协议访问并读取数据时 ...
- 【解决】Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse
ajax获取不到数据: 问题描述: VM379:1 Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse ( 原因分析: 1 ...
- webpack安装报错(Unexpected end of JSON input while parsing near '...e6139ad7957,tarball')
解决方法: 直接执行命令: npm npm cache clean --force 安装成功:
- 报错SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (<anonymous>)的解决方法
报错SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse ()的解决方法 刚刚开始学习node.js会报很多各种各样的 ...
- 93.<报错 SyntaxError: Unexpected token R in JSON at position 0 at JSON.parse (<anonymous>)的解决方法>
@[TOC]( 报错 SyntaxError: Unexpected token R in JSON at position 0 at JSON.parse ()的解决方法) 报错代码: const ...
- 报错 SyntaxError: Unexpected token R in JSON at position 0 at JSON.parse (<anonymous>)的解决方法
报错 SyntaxError: Unexpected token R in JSON at position 0 at JSON.parse ()的解决方法 报错代码: let articles = ...
- 微信小程序报SyntaxError: Unexpected end of JSON input
微信小程序报SyntaxError: Unexpected end of JSON input 这个错误是因为在路由传参的时候 微信小程序解析出来没有正确识别的字符 H5端可以正确使用 解决方法 le ...
- JSON.parse解析字符串报错-SyntaxError: Unexpected token ‘ in JSON at position 报错 并捕获该异常操作
"SyntaxError: Unexpected token ' in JSON at position" 报错原因是因为解析的字符串对象中,JSON.parse无法识别; JSO ...
- php,ajax -->Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>)
解决方案: 1.查找页面是否有注释.输出语句,若有,则删除 2.查看php mysql语句是否有错误(php语句是否存在报错,可以先将JSON.parse()语句注释) 3.将echo json_en ...
最新文章
- 数据结构c语言函数大全,数据结构习题库(c语言版).doc
- mysql 时间点_MySQL 基于时间点与位置恢复
- 【Socket网络编程】2.sockaddr 和 sockaddr_in
- html怎么防止修改数据,HTML防数据采集
- Python 练习: 简单角色游戏程序
- linux系统下c语言程序需要改动的地方,如何在Linux系统环境下进行C语言开发
- Jquery 实现动态加入table tr 和删除tr 以及checkbox的全选 和 获取加入TR删除TR后的数据...
- c++ []是什么意思
- es6 对象中是否有键值_JS获取对象键值对中key值的方法
- linux删除磁盘设备,linux添加,移除scsi设备
- IEEE1588V1-V2理解
- 学生使用腾讯云搭建个人网站
- 淘宝宝贝详情栏固定位置的效果实现
- 擎创喜报 | 名单公布!恭喜入选!
- 苹果手机有4g信号但是微信未连接服务器,苹果5s有显示4g网络但无上微信 是不是那里设置了 今天才出现的...
- 新5G网络架构较复杂 设立面对不少挑战
- uni-app实现PDF预览功能(避坑看这)
- 顶会速递 | ICLR 2020录用论文之元学习篇
- 列表推导式详解:[i for i in L]
- oracle补丁集2020,Oracle发布2020年首批关键补丁更新,多达334个安全补丁