前言
前段时间在做前端开发的过程中遇到一个关于JSON.parse()的使用的报错问题,JSON.parse()通常是用来对JSON对象和字符串之间的相互转换的,所以一般在使用的时候遇到相关报错就是因为在使用的时候没有做相应的非空判断,或者是数据格式错误造成的。那么本文就来分享一下关于使用JSON.parse()进行字符串和JSON对象相互转换的时候遇到的报错问题。
报错提示
具体的报错信息如下所示:
vue.esm.js?efeb:628 [Vue warn]: Error in created hook: "SyntaxError: Unexpected token u in JSON at position 0"
found in
---> <PositionDetail> at src/views/TalentScout/PositionDetail.vue
<Layout> at src/views/Layout.vue
<App> at src/App.vue
<Root>
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at VueComponent.created (PositionDetail.vue?b477:114)
at invokeWithErrorHandling (vue.esm.js?efeb:1872)
at callHook (vue.esm.js?efeb:4244)
at VueComponent.Vue._init (vue.esm.js?efeb:5031)
at new VueComponent (vue.esm.js?efe