您的位置:首页 > 理论基础 > 数据结构算法

encode_json 会对给定的Perl的数据结构转换为一个UTF-8 encoded, binary string.

2016-07-11 07:49 253 查看
use JSON qw/encode_json decode_json/ ;
use Encode;
my $data = [
{
'name' => 'Ken' ,
'age' => 19
},
{
'name' => '测试' ,
'age' => 25
}
];
print encode_utf8("'name' => '测试'");
print "\n";
my $json_out = encode_json ( $data );
print $json_out;
print "\n";

encode_json

$json_text = encode_json $perl_scalar
Converts the given Perl data structure to a UTF-8 encoded, binary string.

This function call is functionally identical to:

$json_text = JSON->new->utf8->encode($perl_scalar)

encode_json 会对给定的Perl的数据结构转换为一个UTF-8 encoded, binary string.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: