<pre name="code" class="cpp">Perl 的 decode_json() 函数用于在 Perl 中解码 JSON。这个函数返回从 JSON 解码到适当 Perl 类型的值
use JSON qw/encode_json decode_json/;
my $data = [
{
'name' => 'Ken',
'age' => 19
},
{
'name' => 'xy',
'age' => 25
}
];
my $json_out = encode_json($data);
print $json_out;
print "\n";
my $array = decode_json($json_out);
use Data::Dumper;
my $xx= Dumper($array);
print "111111111\n";
print $xx;
print "\n";
print "222222222222222\n";
print $array->[1]{name};
jrhmpt01:/root/wx# perl y1.pl
[{"name":"Ken","age":19},{"name":"xy","age":25}]
111111111
$VAR1 = [
{
'name' => 'Ken',
'age' => 19
},
{
'name' => 'xy',
'age' => 25
}
];
222222222222222
xy
jrhmpt01:/root/wx#
decode_json 必须是unicode形式的字符,Dump不支持显示unicode形式的中文 只能 \x{xxxx}
perl json encode_json decode_json
最新推荐文章于 2023-04-02 08:17:14 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)