之前我开始写的时候在传递的一方使用JSON.stringify()去进行转换
然后在接收的一方使用JSON.parse()进行转换,这样的话会报错

这个是提示转换json对象方法没有成功看下json字符串是否正确
那么 如何解决?
首先在传的一方使用:JSON.stringify() 以及encodeURIComponent()进行转换
例如:
var arr=JSON.stringify(e)
this.$router.push("/details?obj="+encodeURIComponent(arr))
在接收的一方使用:decodeURIComponent() 以及 JSON.parse()进行转换
var list = decodeURIComponent(this.$route.query.obj);
console.log(JSON.parse(list));
这样的话就可以解决了这个报错信息

本文介绍了一种使用JSON.stringify(), encodeURIComponent(), decodeURIComponent() 和 JSON.parse() 方法来安全地在网络上传输JSON数据的技巧,避免了直接使用JSON.parse()可能引发的错误。
3240

被折叠的 条评论
为什么被折叠?



