Search code examples
javascriptangularjsencodeuricomponentdecodeuricomponent

DecodeURIComponent is not supporting for %uXXXX encoded component


DecodeURIComponent is not supporting for few encoded component

I am sending JD with bulletin format in my json , in restapi . So I am encoding the jd and sending. this works properly without any issues.But when I am trying to decode the encoded JD , I am getting error as URI malformed

var jd = "Where are bullets most often used?

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


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

}

Decoding :

var jd = decodeURIComponent(jd);

thi is my encoded jd I am getting from response.

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

Solution

  • you have to unescape it first

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