我使用Perl的TMDB
模塊perl的訪問多維數組
我將如何得到本例中的元素從下面的代碼,所以
my $width = '1000'
和my $file_path = "/yDIVWFJqFLIeS8E1R6GG9uwPMS3.jpg"
my @images = $movie->images;
# print " <p>backdrops </p>";
print OUT JSON::to_json(\@images) ; ## Dump.txt below
foreach my $image (@images) {
#print $movie->cast;
my $backdrops = $image->{backdrops};
my $posters = $image->{posters};
#print " <p>backdrops" . JSON::to_json(\@backdrops) . "</p>";
foreach my $backdrop ($image{backdrops}) {
my $width = $backdrop->{width};
my $file_path= $backdrop->{file_path};
print " <p>backdrops </p>";
print "<div>width : $width <br />$file_path : $file_path </div>";
}
}
轉儲樣本.txt
[{
"posters":
[{"vote_average":5.89446589446589,"aspect_ratio":0.67,"width":1000,"file_path":"/yDIVWFJqFLIeS8E1R6GG9uwPMS3.jpg","vote_count":11,.....}],
"id":60304,
"backdrops":
[{"vote_average":5.49206349206349,"aspect_ratio":1.78,"width":1920,"file_path":"/4wieJ74tXkZDMiiwJ6yMr7LgSpR.jpg","vote_count":11,.....}]
}]
背景圖循環應該是'$ image - > {backdrops}'不是'$ image {backdrops}' – user1937198
請看本教程:http://perldoc.perl.org/perlreftut.html – mzedeler