Heim > Fragen und Antworten > Hauptteil
Der js-Code lautet wie folgt
var e = a.charCodeAt(t).toString(16);这一行不明白
function encode_unicode_param(a) {
for (var s = "", t = 0; t < a.length; t++) {
var e = a.charCodeAt(t).toString(16);
s += 2 == e.length ? "n" + e: e
}
return s
}
滿天的星座2017-06-22 11:53:54
python3 下:
def encode_unicode_param(s):
results = []
for char in s:
h = hex(ord(char))[2:]
format_string = 'n{}' if len(h) == 2 else '{}'
results.append(format_string.format(h))
return ''.join(results)