Unexpected token u in JSON at position 0 at JSON.parse ()

一、前言

  在使用 JS 中,不严谨的写法,会导致项目中出现未知的问题。所以就是大家说的:项目的中bug是一直存在的,缺少触发条件罢了。

二、解决

  Unexpected token u in JSON at position 0    at JSON.parse (<anonymous>)

  如果在js中,出现  Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) ,这是一个简单的问题,如何快速破解。其实遇见这个问题稍稍一看,就是转换出错,也就是说本是 JSON 字符串,但是其实是一个空对象。所以我们只要在使用 JSON.parse () 前,判断需要转发的对象是不是null,如果是null,我们可以给他赋值为一个空的 JSON 字符串。

上一篇:ionic 项目 错误 ERROR SyntaxError: Unexpected token < in JSON at position 0


下一篇:解决Vuejs报错error: Unexpected console statement (no-console)