PUT API请求返回JSON主体错误

问题描述 投票:0回答:1

[我试图通过发送放置请求来更新通讯组列表,当我运行此代码并通过给它提供JSON正文在邮递员中对其进行测试时,我在node.js终端中收到此错误,说明为SyntaxError: Unexpected end of JSON input ...任何想法我应该改变什么?

我的PUT API请求

 app.put("/api/Dls/Add/:groupId" , (req, res) => {
    const response = {
      success: false
    };
    if (Authorized.myToken) {
      response.success = true;
      response.data = {};
      var options = {
        method: 'PUT',
        url: 'https://SomeAPI.com/' + req.params.groupId,
        headers:
        {
          Accept: 'application/json',
          Authorization: 'Bearer' + ' ' + Authorized.myToken
        },

        body: JSON.stringify(req.body)

      };
      request(options, function (error, response, body){
        if (error) {
          console.log(error);
          return;
        }
        const data = response.body;
        const dls = JSON.parse(data)
        return res.json(dls);

      });
    }
 }); 

我正在通过邮递员传递的JSON正文以测试API调用

{
        "groupId": "123456789",
        "SomeField1": null,
        "SomeField2": "xxxxxxxxx",
        "SomeField3": true,
        "SomeField4": "xxxxxxxxx",
        "SomeField5": "xxxxxxxxx",
        "SomeField6": [
            "xxxxxxxxx"
        ],
        "SomeField7": "xxxxxxxxx",
        "SomeField8": "xxxxxxxxx",
        "SomeField9": "xxxxxxxxx",
        "SomeField10": "xxxxxxxxx",
        "SomeField11": [],
        "SomeField12": "xxxxxxxxx",
        "SomeField13": null,
        "SomeField14": false,
        "SomeField15": ["xxxxxxxxx"]
}

任何反馈表示赞赏!

node.js json api put
1个回答
0
投票

如果您在此处发布的JSON是您通过邮递员传递的真实JSON,那么它不是有效的JSON,因为您具有相同的名称属性。当我说有效时,表示发布到端点后会得到类似的内容。

© www.soinside.com 2019 - 2024. All rights reserved.