Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何映射解码的json perl_Json_Perl_Perl Hash - Fatal编程技术网

如何映射解码的json perl

如何映射解码的json perl,json,perl,perl-hash,Json,Perl,Perl Hash,我无法映射解码json内容中的所有URL。。。我尝试了,但得到错误:不是哈希引用 $text = decode_json($document); #print Dumper($text); my @urls = map { $_->{'uri'} } @{$text->{children}->{children}}; print @urls; 在这里解码的JSON,我需要捕获URL…当我运行时没有一个->{children}我没有得到错误,但不能得到URL只有一些变量,如pa

我无法映射解码json内容中的所有URL。。。我尝试了,但得到错误:不是哈希引用

$text = decode_json($document);
#print Dumper($text);
my @urls = map { $_->{'uri'} } @{$text->{children}->{children}};
print @urls;
在这里解码的JSON,我需要捕获URL…当我运行时没有一个->{children}我没有得到错误,但不能得到URL只有一些变量,如parets,title,type,等等

$VAR1 = {
          'lastModified' => '1375048740407000',
          'children' => [
                          {
                            'parent' => 1,
                            'children' => [
                                            {
                                              'parent' => 2,
                                              'lastModified' => '1374933801475000',
                                              'type' => 'text/x-moz-place-separator',
                                              'id' => 15,
                                              'title' => '',
                                              'dateAdded' => '1374933801475000'
                                            }
                                          ],
                            'dateAdded' => '1374933800710000',
                            'lastModified' => '1375356010239000',
                            'title' => 'Bookmarks Menu',
                            'id' => 2,
                            'type' => 'text/x-moz-place-container',
                            'root' => 'bookmarksMenuFolder'
                          },
                          {
                            'parent' => 1,
                            'children' => [
                                            {
                                              'parent' => 3,
                                              'charset' => 'UTF-8',
                                              'uri' => 'http://projects.org/#',
                                              'dateAdded' => '1375356057087000',
                                              'lastModified' => '1375356057097000',
                                              'title' => 'projects',
                                              'id' => 24,
                                              'type' => 'text/x-moz-place'
                                            },
                                            {
                                              'parent' => 3,
                                              'charset' => 'UTF-8',
                                              'uri' => 'http://kalja.org/',
                                              'dateAdded' => '1375356063615000',
                                              'index' => 1,
                                              'lastModified' => '1375356063615000',
                                              'title' => 'Kalja.org',
                                              'id' => 25,
                                              'type' => 'text/x-moz-place'
                                            }
                                          ],
                            'annos' => [
                                         {
                                           'flags' => 0,
                                           'value' => 'Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar',
                                           'name' => 'bookmarkProperties/description',
                                           'type' => 3,
                                           'mimeType' => undef,
                                           'expires' => 4
                                         }
                                       ],
                            'dateAdded' => '1374933800710000',
                            'index' => 1,
                            'lastModified' => '1375356065865000',
                            'root' => 'toolbarFolder',
                            'title' => 'Bookmarks Toolbar',
                            'id' => 3,
                            'type' => 'text/x-moz-place-container'
                          },
                          {
                            'parent' => 1,
                            'children' => [],
                            'dateAdded' => '1374933800710000',
                            'index' => 2,
                            'lastModified' => '1374933800710000',
                            'title' => 'Tags',
                            'id' => 4,
                            'type' => 'text/x-moz-place-container',
                            'root' => 'tagsFolder'
                          },
                          {
                            'parent' => 1,
                            'children' => [],
                            'dateAdded' => '1374933800710000',
                            'index' => 3,
                            'lastModified' => '1375356065865000',
                            'title' => 'Unsorted Bookmarks',
                            'id' => 5,
                            'type' => 'text/x-moz-place-container',
                            'root' => 'unfiledBookmarksFolder'
                          }
                        ],
          'root' => 'placesRoot',
          'type' => 'text/x-moz-place-container',
          'id' => 1,
          'title' => '',
          'dateAdded' => '1374933800710000'
        };

提前感谢

您有嵌套结构,因此需要嵌套的
地图

my @urls = map { 
    map { $_->{'uri'} } @{$_->{children}} 
}
@{$text->{children}};

如果要跳过没有
uri的子级
,则
map{$\->{'uri'}或()}..