搜索
热搜: 活动 交友 discuz
Hi~登录注册
查看: 3294|回复: 3

SyntaxError: Unexpected token ' in JSON at position 0

[复制链接]

1

主题

1

帖子

16

积分

新手上路

Rank: 1

积分
16
发表于 2018-12-8 14:41:42 | 显示全部楼层 |阅读模式
messenger职能助手用官方的js代码'use strict';
const PAGE_ACCESS_TOKEN = process.env.PAGE_ACCESS_TOKEN;
// Imports dependencies and set up http server
const
  request = require('request'),
  express = require('express'),
  body_parser = require('body-parser'),
  app = express().use(body_parser.json()); // creates express http server

// Sets server port and logs message on success
app.listen(process.env.PORT || 1337, () => console.log('webhook is listening'));

// Accepts POST requests at /webhook endpoint
app.post('/webhook', (req, res) => {  

  // Parse the request body from the POST
  let body = req.body;

  // Check the webhook event is from a Page subscription
  if (body.object === 'page') {

    body.entry.forEach(function(entry) {

      // Gets the body of the webhook event
      let webhook_event = entry.messaging[0];
      console.log(webhook_event);


      // Get the sender PSID
      let sender_psid = webhook_event.sender.id;
      console.log('Sender ID: ' + sender_psid);

      // Check if the event is a message or postback and
      // pass the event to the appropriate handler function
      if (webhook_event.message) {
        handleMessage(sender_psid, webhook_event.message);        
      } else if (webhook_event.postback) {

        handlePostback(sender_psid, webhook_event.postback);
      }

    });
    // Return a '200 OK' response to all events
    res.status(200).send('EVENT_RECEIVED');

  } else {
    // Return a '404 Not Found' if event is not from a page subscription
    res.sendStatus(404);
  }

});


每次有json数据时,内置的JSON解析就会报错:
SyntaxError: Unexpected token ' in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError (F:\facebook_game\webhook\node_modules\body-parser\lib\types\json.js:158:10)
    at parse (F:\facebook_game\webhook\node_modules\body-parser\lib\types\json.js:83:15)
    at F:\facebook_game\webhook\node_modules\body-parser\lib\read.js:121:18
    at invokeCallback (F:\facebook_game\webhook\node_modules\raw-body\index.js:224:16)
    at done (F:\facebook_game\webhook\node_modules\raw-body\index.js:213:7)
    at IncomingMessage.onEnd (F:\facebook_game\webhook\node_modules\raw-body\index.js:273:7)
    at IncomingMessage.emit (events.js:182:13)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)


有朋友遇到过这种问题吗?
回复

使用道具 举报

2

主题

12

帖子

103

积分

实习版主

Rank: 7Rank: 7Rank: 7

积分
103
发表于 2018-12-10 10:42:40 | 显示全部楼层
你把你的json放json.cn里面 如果能解析出来再放上去  可能要求 的json的格式很严格
回复 支持 1 反对 0

使用道具 举报

0

主题

24

帖子

101

积分

注册会员

Rank: 2

积分
101
发表于 2019-3-21 12:01:22 | 显示全部楼层
2019年最新免费刷q币网址是:【http://qq2019.imotor.com 】——2019年唯一免费刷q币方法,目前只能通过手机APP下载软件来刷q币了,必须在自己手机自带的APP里面下载软件来刷q币。新的版本新的技术没有什么办不到的,只是不容易被发现罢了,
真是好东西,顶啊!
◇刷q币器⊕自动刷q币软件◎qq黑客免费刷q币器软件□♂2018大洋刷q币q点器▃高仿真刷q币软件△怎样刷q币免费▃◆qq刷q币▓刷q币代码回刷q币软件免费版▁◆刷q币代码▄怎么免费刷q币回免费刷q币软件最新▼〓刷q币▂刷q币软件免费版♀免费刷q币软件下载{特殊字符}
回复 支持 反对

使用道具 举报

0

主题

3

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2019-6-18 17:37:08 | 显示全部楼层
河北快3 thanks i will thing that
回复 支持 反对

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 立即注册

快速回复 返回顶部 返回列表