perl json encode_json decode_json

来源:互联网 发布:房间改造软件 编辑:程序博客网 时间:2024/06/05 18:51
<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          }        ];222222222222222xyjrhmpt01:/root/wx# decode_json 必须是unicode形式的字符,Dump不支持显示unicode形式的中文 只能 \x{xxxx}


                                             
0 0