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));