I think the JSON parser is able to decode this unicode escapes
correctly!

The JSON parser will not decode an pure string to you have to wrap the
string into array syntax, and extract after parsing:

mbj@mbj ~ $ irb                                                                                                                                                                    
irb(main):001:0> require 'json'
=> true                                                                                                                                                                             
irb(main):002:0> x = '\u041f\u0440\u0438\u0432\u0435\u0442!'                                                                                                                        
=> "\\u041f\\u0440\\u0438\\u0432\\u0435\\u0442!"                                                                                                                                    
irb(main):003:0> JSON.parse('["'+x+'"]')[0]
=> "妤把我志快找!"                                                                                                                                                                        
irb(main):004:0> 

IMHO better than eval ;)


On Mon, Jun 28, 2010 at 01:22:33PM +0900, Gary Wright wrote:
> 
> On Jun 27, 2010, at 8:33 AM, born in USSR wrote:
> 
> > I have string: '\u041f\u0440\u0438\u0432\u0435\u0442!' and i need to
> > convert it to string such as '扭把我志快找!'.
> > I can convert string to '041f 0440 0438 0432 0435 0442', then convert to
> > decimal and at the end convert each code to character with function:
> 
> If I understand you correctly you can leverage Ruby's parser to
> interpret your string literal:
> 
> irb> x = '\u041f\u0440\u0438\u0432\u0435\u0442!'
> => "\\u041f\\u0440\\u0438\\u0432\\u0435\\u0442!"
> irb> eval("\"#{x}\"")
> => "妤把我志快找!"
> 
> Be careful though with eval, make sure your string to be evaluated doesn't contain any untrusted code.
> 
> Gary Wright