简体   繁体   中英

NodeJS create JSON array for Slack incoming webhook

I am currently working on getting my incoming Webhook application written in Node.JS to get work with this API: https://api.slack.com/incoming-webhooks .

My problem is that the JSON string for Slack has to configured with " these quotation marks and if I create a simple JSON string in Node.JS, Slack says that the string isn't valid.

var text = "New Commit";
var form = '{"text": "' + text + '" }';

The above code works, but looks pretty ugly and when I add a \\n' to indicate a new line, the \\n is directly converted into a new line and not sent within the string, so Slack says again the JSON string isnt valid.

正如tandrewnichols所提到的,我需要使用JSON.stringify并创建一个对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM