perl json encode_json decode_json

<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 "
";


my $array = decode_json($json_out);
use Data::Dumper;

my $xx= Dumper($array);        
print "111111111
";    
print $xx;        
print "
"; 
print "222222222222222
";
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}





                                    
原文地址:https://www.cnblogs.com/hzcya1995/p/13351068.html