javascriptutf-8decode

javascript chinese/japanese character decoding


I created a JSONP function on the server and returns a UTF-8 encoded json object like this

applyLocalization({"Name":"%E5%90%8D%E5%89%8D","Age":"%E5%B9%B4%E9%BD%A2"});

on my javascript on the client side, i want to convert the garbled part to their original state like

{"Name":"名前", "Age":"年齢"}

I tried $.parseJSON() but it doesnt work


Solution

  • You can use decodeURIComponent to decode urlencoded strings like yours

    decodeURIComponent('%E5%90%8D%E5%89%8D');
    //result: '名前'