dear forum members,
my query must be a silly, but I have been finding hard to undestand json. Apart from knowing it is a key value pair, I cannot undertand much. How to initiate it. How to loop over it. How to print it without using print Dumper.
Is it a hash or is it reference?
example:
my $son = '{
}';
my $r=decode_json($son);#cannot understand why I need to do
$r->{"trans2"}[0]="90";
$r->{"trans2"}[1]="20";
print "\n\n";
#print Dumper \$r; # without dumper, how can I iterate using for loop?
print $r->{"trans2"}[0],"\n"; #hard coded
print $r->{"trans2"}[1],"\n"; #hard coded
Above, I want 2 values in trans1 key.
How do I iterate over keys in json object?
Sorry, I have posted this in wrong forum. Admins, pleae move this thread to respective forum
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.