javascript chinese/japanese character decoding

10,636

Solution 1

You can use decodeURIComponent to decode urlencoded strings like yours

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

Solution 2

You could use the decodeURIComponent function. But you shouldn't be URL encoding your javascript strings. You should send them as UTF-8 strings as-is. Javascript is capable of understanding them.

Share:
10,636
Chinchan Zu
Author by

Chinchan Zu

初めまして真斗です!プログラミング初心者ですが、これからいろいろ皆様とお尋ねすることが多いと思いますので是非宜しくお願いします。私も精一頑張りますので皆様と支えながらプログラミングしていきたいと思います。 Hi, my name is MATO, a beginner programmer from Japan. I joined here to learn from great programmers around the world. I want to do my best so If i stumble upon some roadblocks in programming please help me. (sorry for my bad english)

Updated on June 04, 2022

Comments

  • Chinchan Zu
    Chinchan Zu almost 2 years

    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

  • Chinchan Zu
    Chinchan Zu over 12 years
    i tried to send them as is but the japanese part become series of question marks so i decided to encode them then decode on the client... is there anything wrong?
  • Darin Dimitrov
    Darin Dimitrov over 12 years
    @ChinchanZu, yes there must be something wrong with your page or server. Maybe you are no setting the correct response content type or maybe your page is not correctly encoded.