DecodeURIComponent 不支持少数编码组件
我正在restapi中以我的json中的公告格式发送JD。所以我对 jd 进行编码并发送。这可以正常工作,没有任何问题。但是当我尝试解码编码的 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));
关于javascript - DecodeURIComponent 不支持 %uXXXX 编码组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50539403/