意外的令牌"在位置 0 处的 JSON

问题描述

我在写 axios 帖子时收到此错误。我传递的数据是从tesseract js识别的数据。下面是示例代码:

        await worker.load();
        await worker.loadLanguage('eng');
        await worker.initialize('eng');
        worker._currentJob = null;
        const { data: { text } } = await worker.recognize(file);
        let newText = JSON.stringify(text);
        let replace = newText.replace(/\\/g,'');

        try {
            console.log(file);
            const res = await axios.post('http://localhost:5000/api/image',JSON.stringify(replace),{
                headers: {
                    'Content-Type': 'application/json','Accept': 'application/json'
                }
            });
            console.log("Response",res);
        } catch(err) {
            if(err === 500) {
                console.log("There was a problem with the server");
            } else {
                console.log("Error: ",err.response);
            }
        }
        
        console.log(text);
        await worker.terminate();

文本变量gets=

各种归属之夜的温和辉煌! 疯狂工作愿景的母亲!冰雹 看着你的滑翔,同时带着水光 你虚弱的眼睛透过蓬松的面纱闪烁着; 当你爱你苍白的球体 在聚集的黑暗背后失去了高处; 当你冲出风云 你平静的闪电照亮了苏醒的天空。

替换变量gets= “多姿多彩的夜晚的温和光彩!n疯狂工作的幻象之母!在水光中看着你的滑翔高;n当你冲出风破的云层时,你平静的闪电在苏醒的天空上。n”

有人可以帮助我吗?也是 api/image 端点,接收一个字符串

 image: {
        type: String,required: true
    }

当我传递一个字符串时,它适用于邮递员。但不是这里。

请帮忙

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...