DecodeURIComponent 不支持 %uXXXX 编码组件

DecodeURIComponent is not supporting for %uXXXX encoded component

DecodeURIComponent 不支持少数编码组件

我在 json 和 restapi 中发送公告格式的 JD。所以我正在编码 jd 并发送。这在没有任何 issues.But 的情况下正常工作,当我尝试解码编码的 JD 时,我收到错误消息,因为 URI 格式错误

var jd = "Where are bullets most often used?

 - Technical writing
 - Reference works
 - Notes
 - Presentations";


var json ={
"job":encodeURIComponent(escape(jd));

}

解码:

var jd = decodeURIComponent(jd);

这是我从响应中得到的编码 jd。

Where%20are%20bullets%20most%20often%20used%3F%0A%uF0B7Technical%20writing%0A%uF0B7Sub%20bullet%0A%uF0B7Reference%20works%0A%uF0B7Notes%0A%uF0B7Presentations%0A%uF0B7Lists%0AAn%20alternative%20method%20is%20to%20use%20a%u807Dnumbered%20list%3A%0A1.Technical%20writing%0A2.Reference%20works%0A3.Notes%0A4.Presentations%0A5.Lists

你必须先unescape

var jd = decodeURIComponent(unescape(json.job));

避免使用 escape()

来自文档:

escape()

The escape() function computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.

Description

The escape function is a property of the global object. Special characters are encoded with the exception of: @*_+-./

The hexadecimal form for characters, whose code unit value is 0xFF or less, is a two-digit escape sequence: %xx. For characters with a greater code unit, the four-digit format %uxxxx is used.

Deprecated. Not for use in new websites.

— MDN JavaScript Reference - escape()

来自维基百科:

There exists a non-standard encoding for Unicode characters: %uxxxx, where xxxx is a UTF-16 code unit represented as four hexadecimal digits. This behavior is not specified by any RFC and has been rejected by the W3C. The third edition of ECMA-262 still includes an escape function that uses this syntax, along with encodeURI and encodeURIComponent functions, which apply UTF-8 encoding to a string, then percent-escape the resulting bytes.

— Wikipedia - Percent encoding - Non-standard implementations