使用Python';s unquote()用于Node.js
我通过webhook接收以下格式的数据使用Python';s unquote()用于Node.js,python,node.js,Python,Node.js,我通过webhook接收以下格式的数据 { "Body": "Test+131415+5%2B5%3D10", "To": "whatsapp%3A%2B4915735992273", "From": "whatsapp%3A%2B491603817902", } 在Python中,我可以使用以下函数来转换数据。但是,我找不到使用Node.js获得相同结果的方法 def get_from(from: str) -> int: """ Replace %xx e
{
"Body": "Test+131415+5%2B5%3D10",
"To": "whatsapp%3A%2B4915735992273",
"From": "whatsapp%3A%2B491603817902",
}
在Python中,我可以使用以下函数来转换数据。但是,我找不到使用Node.js获得相同结果的方法
def get_from(from: str) -> int:
"""
Replace %xx escapes by their single-character equivalent.
Only return the part that is behind the plus sign.
"""
receiver = unquote(receiver).split("+")
return receiver[1]
def get_body(body: str) -> str:
"""
Replace %xx escapes by their single-character equivalent.
_plus additionally replaces plus signs by spaces.
"""
body = unquote_plus(body)
return body
nodejs中的urlib.parse.unquote等效项为 nodejs中没有urlib.parse.unquote_plus的等效项 但你可以自己做,如下所示
const { unescape } = require('querystring');
const data = {
"Body": "Test+131415+5%2B5%3D10",
"To": "whatsapp%3A%2B4915735992273",
"From": "whatsapp%3A%2B491603817902",
};
function getFrom(from) {
return unescape(from).split('+')[1];
}
function getBody(body) {
return unescape(body.replace(/\+/g, ' '));
}
console.log(getFrom(data.From));
console.log(getBody(data.Body));