2013-08-02 3 views
0

내 문자열은입니다.javascript url 디코딩이 작동하지 않습니다.

var str = "Mehmet%2bAli%2b%c3%96zcan"; 

그리고 문자열을 가져오고 싶습니다.

var strDecoded = "Mehmet Ali Özcan"; 

나는 다음을 모두 시도했다.

strDecoded = decodeURIComponent(str); // Fails; 
strDecoded = decodeURIComponent((str + '').replace(/\+/g, '%20')); // Fails 
strDecoded = _decodeURI(str); // Fails 


function _decodeURI(str) { 
    str = decodeURI(str); 
    str = str.replace(/%27/g, "'"); 
    return str; 
} 

올바른 문자열을 얻으려면 어떻게해야합니까? 어떤 생각? 나를 위해

+0

이 http://stackoverflow.com/questions/3803716/how-can-i-decode-a-url-with-jquery를 참조하십시오. –

+0

이것은 잘못된 문제입니다. 문제는 문자열이 어떻게 생성되는지, 공백은 '+'또는 '% 2b'가 아니라 '% 20'이어야한다는 것입니다. – Esailija

답변

3

다음 작품 :

decodeURIComponent("Mehmet%2bAli%2b%c3%96zcan").replace(/\++/g, ' ');