简体   繁体   English

UncaughtUncaught语法错误,JSON中位置0处的意外令牌u

[英]UncaughtUncaught syntax error unexpected token u in JSON at position 0

I'm currently using the Algolia JS API but for some reason I keep randomly getting the following error in console: 我目前正在使用Algolia JS API,但由于某些原因,我在控制台中不断出现以下错误:

UncaughtUncaught syntax error unexpected token u in JSON at position 0

My current code looks like this: 我当前的代码如下所示:

    var params  = {
        hitsPerPage: 10,
        page: 0,
        facets: '*'
    }   
    index.search('some search term', params, function load_search_products_callback(err, content) {
        console.log(content);
    });

The problem is that the error occurs before the console.log(content) part of the code is run, so I'm unable to actually what the problem is or where it's happening. 问题是该错误发生在代码的console.log(content)部分运行之前,因此我无法真正知道问题的所在或发生的位置。

From looking at your code I can predict it is a JS code. 通过查看您的代码,我可以预测它是JS代码。

UncaughtUncaught syntax error unexpected token u in JSON at position 0 occur when you pass undefined to JSON.parse as an argument. 当您将undefined传递给JSON.parse作为参数时,会UncaughtUncaught syntax error unexpected token u in JSON at position 0发生UncaughtUncaught syntax error unexpected token u in JSON at position 0

var a = undefined; JSON.parse( a );

This can be the issue in your code. 这可能是您的代码中的问题。 You need to figure out where this is happening in your code. 您需要弄清楚代码中发生了什么。

I hope that'll help 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM