Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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; }

Comment on Re^5: UTF8 fun and games again
Download Code
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 making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2015-11-27 00:57 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (710 votes), past polls