HI all,

How can we retrieve encode_json value which is in encode_json associative array formate.

my code is as follows to doing that.

%responce_array1=(); %responce_array2=(); $responce_array1{'REQUEST'}{'Items'}{0}{'ItemName'}='demoName0'; $responce_array1{'REQUEST'}{'Items'}{1}{'ItemName'}='demoName1'; $responce_array1{'REQUEST'}{'Items'}{2}{'ItemName'}='demoName2'; my $itemjson_ary1 = encode_json \%responce_array1; $responce_array2{'item_json_array'}=$itemjson_ary1; my $itemjson_ary2 = encode_json \%responce_array2; print $itemjson_ary2; $jsonary='{"item_json_array":"{\"REQUEST\":{\"Items\":{\"1\":{\"ItemNa +me\":\"demoName1\"},\"0\":{\"ItemName\":\"demoName0\"},\"2\":{\"ItemN +ame\":\"demoName2\"}}}}"}'; $dec_json_obj = decode_json $jsonary; $temp=$dec_json_obj->{item_json_array}; $dec_json_obj = decode_json $temp; $temp=$dec_json_obj->{REQUEST}; #hash form $dec_json_obj=&get_hash_to_str($temp); $temp=$dec_json_obj->{Items}; $dec_json_obj=&get_hash_to_str($temp); $temp=$dec_json_obj->{0}; $dec_json_obj=&get_hash_to_str($temp); print $temp=$dec_json_obj->{ItemName}; sub get_hash_to_str($temp) { my $temp=$_[0]; my $enc_json_req = encode_json $temp; print"<br>"; print $enc_json_req; print"<br>"; my $dec_json_obj = decode_json $enc_json_req; return $dec_json_obj; } Here i am sending values like these to retrieve 0 th element of item and get ItemName $temp=$dec_json_obj->{0}; $dec_json_obj=&get_hash_to_str($temp); print $temp=$dec_json_obj->{ItemName};

I want to get all the values of 0 th 1 st 2 nd .... ItemName values using loop. Because it is not feasible to pass single -single values like 0,1,2...

Thanks...


In reply to How can we retrieve encode_json value which is in encode_json associative array formate. by deepakgate6

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.