我使用JSON::Parse
解码json文件。当我将它转储到文件时,它看起来像下面打印。我需要提取' url'来自每个存储库。我怎么能这样做呢?我试图访问元素,但似乎无法访问它们。有什么建议吗?
我如何解码.json文件:
my $json_hash_ref = {};
$json_hash_ref= json_file_to_perl ($REPO_JSON_FILE) or confess "No repos found";
这是数据转储:
$VAR1 = {
'repositories' => [
{
'size' => 2970,
'watchers' => 49,
'created_at' => '2012-03-20T05:04:42Z',
'url' => 'http://github.cerner.com/aeon-core/aeon-topology',
'open_issues' => 0,
'followers' => 49,
'owner' => 'aeon-core',
'has_downloads' => 1,
'has_issues' => 0,
'language' => 'Java',
'pushed' => '2014-06-17T18:32:37Z',
'private' => ${\$VAR1->{'repositories'}[0]{'has_issues'}},
'name' => 'aeon-topology',
'score' => '1',
'has_wiki' => ${\$VAR1->{'repositories'}[0]{'has_issues'}},
'pushed_at' => '2014-06-17T18:32:37Z',
'description' => '',
'username' => 'aeon-core',
'created' => '2012-03-20T05:04:42Z',
'homepage' => '',
'forks' => 59,
'fork' => ${\$VAR1->{'repositories'}[0]{'has_issues'}},
'type' => 'repo'
},
{
.....
},...
答案 0 :(得分:2)
my @urls = map $_->{url}, @{ $json_hash_ref->{repositories} };
有关遍历深层数据结构的详细信息,请阅读perl references tutorial。