Moon
Moon

Reputation: 22565

How to decode stringified unicode?

I'm passing a stringfied string to Java using Ajax.

$.ajax({
    url: "url",
    data: {
       item: JSON.stringify( object with unicode string values ) 
    }
});

I used to parse that in PHP with urldecode and all the characters decoded very well. Now, I need to do that in Java. I tried URLDecoder.decode(string, "UTF-8"), but it didn't work. What should I use instead?

Updated: by "didn't work", I mean I get the following result:

title:"æä¼æ æ¿ä» (from JAVA)

Instead of title:"最优惠房 (from PHP)

Updated 2 :

It looks like I have to use the following before request.getParameter:

request.setCharacterEncoding("UTF-8") 

And my Ajax request must be of POST type.

Upvotes: 1

Views: 799

Answers (1)

dacwe
dacwe

Reputation: 43504

Why not use some existing library that will do it automatically? Check out:

Upvotes: 2

Related Questions