centos6.5:/root/test#cat a1.pl
use JSON qw/encode_json decode_json/;
use Encode;
my $data = [
{
'name' => '科比',
'age' => 19
},
{
'name' => '乔丹',
'age' => 25
}
];
my $json_out = encode_json($data);
print $json_out;
print "\n";
centos6.5:/root/test#perl a1.pl
[{"name":"ç§æ¯","age":19},{"age":25,"name":"ä¹ä¸¹"}]
$json_text = encode_json $perl_scalar
Converts the given Perl data structure to a UTF-8 encoded, binary string.
encode_json 转换给定的Perl 数据结构为一个UTF-8编码的 ,2进制字符串
decode_json
$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 referenc.
和encode_json相反,期望一个UTF-8 2进制字符串和尝试解析一个UTF-8编码的JSON 文本,返回一个结果的参考
decode_json 必须是unicode形式的字符,Dump不支持显示unicode形式的中文 只能 \x{xxxx}
decode_json 必须是unicode形式的字符