Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: JSON Structure Question

by roboticus (Chancellor)
on May 23, 2013 at 13:10 UTC ( [id://1034945]=note: print w/replies, xml ) Need Help??


in reply to JSON Structure Question

omegaweaponZ:

Untested, but I'd try something like:

for my $key (sort keys %$data) { # $key should be 1, 2, then 3 here... for my $subject (sort keys {$data->{$key}) { # $subject should be subject1, then subject 2 here if ($subject eq "subject1") { print "$data->{$key}{$subject}\n"; } elsif ($subject eq "subject2" { # subject2 has arrayref of one item, # an href, with two keys: print "$data->{$key}{$subject}[0]{subject3}\n"; print "$data->{$key}{$subject}[0]{subject4}\n"; } } }

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: JSON Structure Question
by omegaweaponZ (Beadle) on May 23, 2013 at 15:36 UTC
    This is the closest to what I'm looking for, as I can generate all the hashes, but I have yet to get each value. Just to clarify, I already can get every other value within the parenthesis of each json line, So everything within 1 {} I can get! The issue is I actually want to record and store the value of 1 itself, and 2, and 3, and so on, in one giant for loop that encompasses my ability to grab the values of each array within, so they are all assigned line by line
      Figured it out, hash was the way to approach this. But simplistically, all I needed to do was:
      my %hash = %{ $data }; while (my ($key, $value) = each %hash) { print "$key : $value \n";
      Instant first level report out

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1034945]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found