Facebook开发者社区

标题: SyntaxError: Unexpected token ' in JSON at position 0 [打印本页]

作者: rsnm0001    时间: 2018-12-8 14:41
标题: SyntaxError: Unexpected token ' in JSON at position 0
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)


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

作者: FBHappy    时间: 2018-12-10 10:42
你把你的json放json.cn里面 如果能解析出来再放上去  可能要求 的json的格式很严格
作者: aaaaa    时间: 2019-3-21 12:01
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币软件下载{特殊字符}
作者: heian888    时间: 2019-6-18 17:37
河北快3 thanks i will thing that




欢迎光临 Facebook开发者社区 (http://bbs.zcsftek.com/) Powered by Discuz! X3.2