Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSON输入节点的意外结束。js jason.parse()_Javascript_Php_Json - Fatal编程技术网

Javascript JSON输入节点的意外结束。js jason.parse()

Javascript JSON输入节点的意外结束。js jason.parse(),javascript,php,json,Javascript,Php,Json,我正在尝试解析返回的JSON,并附带以下内容(PHP) 这里是创建的JSON{“用户名”:“nil”,“代码”:“nil”,“discorid”:“nil”,“IsVerified”:“nil”,“RobloxID”:“nil”} 我使用node.js获取返回的内容 request('http://example.net/API/verify.php?token=Nf_327&username=' + Username + '&UserId=' + UserID + '&

我正在尝试解析返回的JSON,并附带以下内容(PHP)

这里是创建的JSON<代码>{“用户名”:“nil”,“代码”:“nil”,“discorid”:“nil”,“IsVerified”:“nil”,“RobloxID”:“nil”}

我使用node.js获取返回的内容

request('http://example.net/API/verify.php?token=Nf_327&username=' + Username + '&UserId=' + UserID + '&discordid='+ msg.author.id, function (error, response, body) {
        console.log('error:', error); // Print the error if one occurred 
        console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received 
        console.log('body:', body); // Print the HTML for the Google homepage.
        var info = JSON.parse(body);
        if (info.IsVerified == 'nil') {
            request('http://example.net/API/verify.php?token=Nf_328&username=' + Username + '&UserId=' + UserID + '&discordid='+ msg.author.id, function (error, response, body) {
                console.log('error:', error); // Print the error if one occurred 
                console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received 
                console.log('body:', body); // Print the HTML for the Google homepage.
            });
            msg.reply("Looks like its your first time trying to verify, I have DM'd you instructions on how to verify your account");
        }
    });
但是,每当我尝试运行该函数时,就会得到错误堆栈`

Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Request._callback (/root/InfiusBot/commands/group/verify.js:41:22)
at Request.self.callback (/root/node_modules/request/request.js:188:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/root/node_modules/request/request.js:1171:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/root/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
JSON输入意外结束
在JSON.parse()处
应请求。_回调(/root/InfiusBot/commands/group/verify.js:41:22)
at Request.self.callback(/root/node_modules/Request/Request.js:188:22)
两次(events.js:125:13)
at Request.emit(events.js:213:7)
应要求。(/root/node_modules/request/request.js:1171:10)
在emitOne(events.js:115:13)
at Request.emit(events.js:210:7)
在收到消息时。(/root/node_modules/request/request.js:1091:12)
在Object.onceWrapper(events.js:314:30)
在emitNone(events.js:110:20)
在IncomingMessage.emit(events.js:207:7)
在endReadableNT(_stream_readable.js:1047:12)
at _combinedTickCallback(内部/流程/下一步_tick.js:102:11)
在进程中。_tick回调(内部/process/next_tick.js:161:9)

你知道我在这里遗漏了什么吗?我完全迷路了。

嗯,调用JSON.parse时会发生错误。这意味着返回的主体不是正确的JSON,根据请求文档,这是有意义的,因为它是一个描述HTML页面内容的字符串。这意味着您正在HTML上运行JSON.parse,并且您的url必须是不正确的,您也在发出请求。这可能是因为您正在请求example.net?我觉得基本url应该是不同的url

查找url错误的其他方法是检查当您在浏览器中访问php页面并传递参数时,用户对象是否在屏幕上可见。然后确保url是正确的。最后,您应该检查body对象是否由JSON组成。如果它没有打印出某种形式的JSON,您应该打印正文并通读HTML,因为这可能是PHP正在发送的错误,并且由于某种原因没有被您的错误打印捕获

Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Request._callback (/root/InfiusBot/commands/group/verify.js:41:22)
at Request.self.callback (/root/node_modules/request/request.js:188:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/root/node_modules/request/request.js:1171:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/root/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)