數據格式json
{ "userName":"AlbertYan", "pwd":[ { "pwd1":"pwd1", "pwd2":"g2value" }, { "pwd1":"pwd11", "pwd2":"g2222value" }] }code
#!/usr/bin/perl use Encode; use JSON; use Data::Dumper;xml
my $line ; my $path="D:/PerlDemo/jsonData1.xml";it
if(open (FN ,"$path") ){ while(<FN>){ $line.=$_; } } my $json = new JSON; my $obj = $json->decode($line); my $username = $obj ->{"userName"}; print $username ."\n" ;perl
my @demo ; for my $item(@{$obj->{"pwd"}}){ my $res= $item ->{"pwd1"}; push(@demo , $res); }數據
print "one =$demo[0] two=$demo[1] ";demo
close(FN);while