JSON (2.51)
Because I saw Ben Bullock's terrible review, I comment a bit.
The how-to of (de|en)code_json, (from|to)_json and object methods
are described in the document (each sections and SYNOPSIS).
decode_json expects an UTF-8 (binary) string and identical to:
JSON->new->utf8->decode( $utf8_encoded_text )
So when you correctly use Encode::encode, the below code works.
# $string is a string (or UNICODE)
decode_json( encode('utf8', $string ) );
If decode_json croaks, it's your wrong use of Encode method.
That is not because of the JSON interface difficulty.
Additionally,
from_json is identical to:
JSON->new->decode( $scalar );
# from_json( $scalar, { allow_nonref => 1 } );
# => JSON->new->allow_nonref->decode( $scalar );
So from_json() can take a non utf8 encoded string.
Please see to
Encode, perluniintro,
search.cpan.org/~mlehmann/JSON-XS-2.3...
search.cpan.org/~makamaka/JSON-2.51/l...
makamaka - 2011-05-21T22:04:40 (permalink)
5 out of 7 found this review helpful.
Was this review helpful to you?
Yes
No

