Perl 读取Json 数据

数据格式

{
“userName”:“AlbertYan”,
“pwd”:[

{

“pwd1”:“pwd1”,
“pwd2”:“g2value”

   },
   {

“pwd1”:“pwd11”,
“pwd2”:“g2222value”

}]

}

!/usr/bin/perl

use Encode;
use JSON;
use Data::Dumper;

my $line ;
my $path=“D:/PerlDemo/jsonData1.xml”;

if(open (FN ,“$path”) ){

while(<FN>){
    $line.=$_;
}

}
my $json = new JSON;
my $obj = $json->decode($line);
my $username = $obj ->{“userName”};
print $username .“\n” ;

my @demo ;
for my $item(@{$obj->{“pwd”}}){

my $res= $item ->{"pwd1"};
push(@demo , $res);

}

print “one =$demo[0] two=$demo[1] “;

close(FN);

你可能感兴趣的:(perl)