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

use JSON qw/encode_json decode_json/ ;
use Encode;
my $data = [
     {
         'name' => 'Ken' ,
         'age' => 19
     },
     {
         'name' => '测试' ,
         'age' => 25
     }
];
print encode_utf8("'name' => '测试'");
print "
";
my $json_out = encode_json ( $data );
print $json_out;
print "
";


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.  

原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199634.html