Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^5: UTF8 fun and games again

by ultranerds (Friar)
on Oct 17, 2011 at 18:37 UTC ( #931992=note: print w/replies, xml ) Need Help??

in reply to Re^4: UTF8 fun and games again
in thread UTF8 fun and games again

Ok, for anyone interested - its cos the JSON module needed to explicitly use the utf8 functions JSON->new->utf8 , and then also decode(). I've changed it to this, and it works perfectly now <G>
sub Do_Translate { my ($from,$to,$string) = @_; my $url = "$k +ey&q=$string&source=$from&target=$to"; # print "getting URL: $url \n"; my $ua = LWP::UserAgent->new(); my $body = $ua->get($url); my $json = JSON->new->utf8; my $value = $json->decode( $body->decoded_content ); print "GOT: $value->{data}->{translations}[0]->{translatedText} \n +"; return utf8($value->{data}->{translations}[0]->{translatedText})-> +latin1; }

Replies are listed 'Best First'.
Re^6: UTF8 fun and games again
by anneli (Pilgrim) on Oct 18, 2011 at 08:37 UTC

    Thanks for sharing your solution!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://931992]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2016-10-28 20:08 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (387 votes). Check out past polls.