AWS SNS如何在消息中添加换行符 [英] AWS SNS how to add line breaks in message
问题描述
我正在尝试通过CLI以json格式发送SNS消息.
I'm trying to send SNS messages via CLI in json format.
aws sns publish --cli-input-json "{\"TopicArn\":\"xxx\",\"Message\":\"first line\n second line\",\"Subject\":\"Empty subject\"}"
但是\ n不起作用. "\ r \ n"或"\ n"都不是.我认为该字符串已被SNS转义,因此\ n不起作用.有谁知道如何发送两行消息?(不可以发送2条消息)感谢您的建议!
But the \n doesn't work. Neither is "\r\n" or "\n". I think the string is escaped by SNS so \n doesn't work. Does anyone know how to send a message of 2 lines?(Sending 2 messages is not an option) Appreciate your advice!
推荐答案
我认为\\n
实际上是您想要的.我刚刚通过通过AWS SNS向我的设备发送推送通知进行了测试.
I think \\n
is actually what you are looking for. I've just tested it by sending push notifications to my device through AWS SNS.
因此您的消息应如下所示:
So your message should look like this:
aws sns publish --cli-input-json "{\"TopicArn\":\"xxx\",\"Message\":\"first line\\nsecond line\",\"Subject\":\"Empty subject\"}"
请注意,您不应在换行符后留下空白,否则,新行将从该空格开始.
Note, you should not leave the white space after the line break symbol, otherwise, your new line would start with that space.
这篇关于AWS SNS如何在消息中添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!