未捕获的SyntaxError:位于0的JSON中的意外标记u [英] Uncaught SyntaxError: Unexpected token u in JSON at position 0

查看:250
本文介绍了未捕获的SyntaxError:位于0的JSON中的意外标记u的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在结帐时和单个产品页面上,我在控制台日志中收到以下错误:

Only at the checkout and on individual product pages I am getting the following error in the console log:

VM35594:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at run (layout.min.js:9)
    at app.min.js:1
    at main.min.js:2
    at Object.execCb (require.min.js:112)
    at Module.check (require.min.js:56)
    at Module.<anonymous> (require.min.js:72)
    at require.min.js:11
    at require.min.js:74
    at each (require.min.js:3)

我正在使用单页结帐扩展程序,但是当我禁用时,错误仍会显示。我认为它可能与产品页面上的评论有关(因为我将评论移出选项卡),但撤消该更改并未修复产品页面上的错误。

I am using a one page checkout extension, but when I disable that the error still shows. I thought it might had something to do with the reviews on the product page (as I moved the reviews out of the tabs), but undoing that change didn't fix the error on the product pages.

推荐答案

在控制台中尝试此操作:

Try this in the console:

JSON.parse(undefined)

以下是您将获得的信息:

Here is what you will get:

Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at <anonymous>:1:6

换句话说,您的应用正在尝试解析 undefined ,这是无效的JSON。

In other words, your app is attempting to parse undefined, which is not valid JSON.

这有两个常见原因。第一个是你可能引用一个不存在的属性(如果不是严格模式,甚至是一个不存在的变量)。

There are two common causes for this. The first is that you may be referencing a non-existent property (or even a non-existent variable if not in strict mode).

window.foobar = '{"some":"data"}';
JSON.parse(window.foobarn)  // oops, misspelled!

第二个常见原因是首先未能收到JSON,这可能是由客户造成的忽略错误的副脚本,并在不应该发送请求时发送请求。

The second common cause is failure to receive the JSON in the first place, which could be caused by client side scripts that ignore errors and send a request when they shouldn't.

确保服务器端和客户端脚本都在严格模式并使用 ESLint 。这会让你非常自信没有拼写错误。

Make sure both your server-side and client-side scripts are running in strict mode and lint them using ESLint. This will give you pretty good confidence that there are no typos.

这篇关于未捕获的SyntaxError:位于0的JSON中的意外标记u的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆