javascript - How encode in a right why emojis using node request module?
问题描述
I'm using request module in order to send message to a Telegram bot, everything is fine, except the way I'm display emojis, which don't get printed well
Post request:
request.post({
url: `${this.getApiURL()}/${apiName}`,
formData: payload,
headers: {
'Content-Type': 'application/json',
'Charset': 'utf-8',
}
}, (err, resp, body) => {});
The payload contains a text message with some emojis like:
const _emojis = {
throwingAKiss: '\xF0\x9F\x98\x98',
tearsOfJoy: '\xF0\x9F\x98\x82',
smirkingFace: '\xF0\x9F\x98\x8F'
}
but I'm displaying this symbol ð
解决方案
As a workaround you may have success with using a different unicode notation, i.e.:
const smiley = "\u{1F604}";
For a list of codes you there are emoji tables out there.
Additional, it might ease a bit development overhead by using libaries such as node-emoji (which uses raw emojis under the hood through omnidan/node-emoji json file.
推荐阅读
- node.js - Mongoose Find 不过滤数组内的对象属性(MongoDB 4.4.1)
- javascript - 从reactjs中的URL参数获取原始值
- java - 通过比较其他列表中的项目从列表中删除项目
- python - 如何设置环境变量 DJANGO_SETTINGS_MODULE
- ios - 字典类型中 UserDefaults 保存的数组消失
- java - 是否可以在不创建实例的情况下检查一个类是否在 java 中扩展另一个类?
- mysql - 如何在一个查询中的多个子查询上正确使用多个 group_concats 而没有区别?
- javascript - 在 .c-class-toggler 上的 CoreUI 元素上添加 JS 点击事件
- excel - 如何编写更流畅的宏
- azure - 一次性使用 Powershell 在 azure KeyVault 中添加多个机密的方法