Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: JSON::XS and unicode

by kimmel (Beadle)
on Sep 08, 2012 at 23:01 UTC ( #992539=note: print w/replies, xml ) Need Help??


in reply to Re: JSON::XS and unicode
in thread JSON::XS and unicode

Re-reading JSON::XS there was one key word I missed the first time around. Here is the relevant POD with my emphasis added.

$perl_scalar = decode_json $json_text

The opposite of encode_json: expects an UTF-8 (binary) string and tries to parse that as an UTF-8 encoded JSON text, returning the resulting reference. Croaks on error.
So I need to encode before passing it to decode_json(). Here is the working program
#!/usr/bin/perl use v5.14; use warnings; use utf8::all; use Encode; use JSON::XS qw( decode_json ); my $wl = '{"creche": "crèche", "¥": "£", "₡": "волн" }'; my $pattern_list = decode_json( encode("utf8", $wl) );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992539]
help
Chatterbox?
[karlgoethebier]: holli: total underestimation of Keith...
[karlgoethebier]: ...a common mistake ;-)
[LanX]: a "tone deaf" is the word I was looking for.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-12-13 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (375 votes). Check out past polls.

    Notices?