php 和 perl 的json encode decode

<?php
 
$script_md51=array
(
"tesdf.pl"=>"6775f86ba3d08541dcd9f72d95db7e36" ,
"tesdf2.pl"=>"2222" 
);  
$enj=json_encode($script_md51);  
print "encode=".$enj."\n";
$end= json_decode($enj);
var_dump($end);


?>
结果:
encode={"tesdf.pl":"6775f86ba3d08541dcd9f72d95db7e36","tesdf2.pl":"2222"}
object(stdClass)[1]
  public 'tesdf.pl' => string '6775f86ba3d08541dcd9f72d95db7e36' (length=32)
  public 'tesdf2.pl' => string '2222' (length=4)

 

#!/usr/bin/perl -w
#author:jevons zeng
#1.check pid of squid 2.check access.log of squid 3.check netstat 4.check store server
use strict;
use JSON;
use Data::Dumper;

my $jsonCoder = new JSON();
my $arr;
$arr->{"tesdf.pl"}="6775f86ba3d08541dcd9f72d95db7e36";
$arr->{"tesdf2.pl"}="2222";

print Dumper($arr);
my $enj= $jsonCoder->encode($arr); 

print "enj=".$enj,"\n";
my $j="{\"tesdf.pl\":\"6775f86ba3d08541dcd9f72d95db7e36\",\"tesdf2.pl\":\"2222\"}";


my $jd = $jsonCoder->decode($j); 

print Dumper($jd);
print $jd->{"tesdf.pl"},"\n";
print $jd->{"tesdf2.pl"},"\n";

结果

$VAR1 = {
          'tesdf.pl' => '6775f86ba3d08541dcd9f72d95db7e36',
          'tesdf2.pl' => '2222'
        };
enj={"tesdf.pl":"6775f86ba3d08541dcd9f72d95db7e36","tesdf2.pl":"2222"}
$VAR1 = {
          'tesdf.pl' => '6775f86ba3d08541dcd9f72d95db7e36',
          'tesdf2.pl' => '2222'
        };
6775f86ba3d08541dcd9f72d95db7e36

2222

你可能感兴趣的:(php 和 perl 的json encode decode)