Simple JSON parsing using Perl -


i'm trying parse facebook graph api json results, , i'm having bit of trouble it.

what hoping print number of shares:

my $trendsurl = "https://graph.facebook.com/?ids=http://www.filestube.com"; $json; {   local $/; #enable slurp   open $fh, "<", $trendsurl;   $json = <$fh>; }  $decoded_json = @{decode_json{shares}}; print $decoded_json; 

some of code above extremely puzzling. i've rewritten annotations you.

#!/usr/bin/perl  use lwp::simple;                # cpan use json qw( decode_json );     # cpan use data::dumper;               # perl core module use strict;                     # practice use warnings;                   # practice  $trendsurl = "https://graph.facebook.com/?ids=http://www.filestube.com";  # open files.  unless have file called # 'https://graph.facebook.com/?ids=http://www.filestube.com' in # local filesystem, won't work. #{ #  local $/; #enable slurp #  open $fh, "<", $trendsurl; #  $json = <$fh>; #}  # 'get' exported lwp::simple; install lwp cpan unless have it. # need or similar (http::tiny, maybe?) web pages. $json = get( $trendsurl ); die "could not $trendsurl!" unless defined $json;  # next line isn't perl.  don't know you're going for. #my $decoded_json = @{decode_json{shares}};  # decode entire json $decoded_json = decode_json( $json );  # you'll (it'll print out); comment when done. print dumper $decoded_json;  # access shares this: print "shares: ",       $decoded_json->{'http://www.filestube.com'}{'shares'},       "\n"; 

run , check output. can comment out print dumper $decoded_json; line when understand what's going on.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -