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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值