Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^8: Help with JSON Module

by foggy3657 (Novice)
on Sep 08, 2012 at 10:13 UTC ( #992465=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Help with JSON Module
in thread Help with JSON Module

Thank you. After making a stupid syntax error. $code returns the following using Dumper.

$VAR1 = { 'StatusCode' => 0, 'Products' => [ { 'UnitType' => '100g', 'HealthierAlternativeProductId' => '', 'OfferPromotion' => "Price Drop Was \x{a3} +1.13 Now \x{a3}1.00 ", 'ProductId' => '254881114', 'EANBarcode' => '5000175411118', 'MaximumPurchaseQuantity' => 99, 'CheaperAlternativeProductId' => '', 'ProductType' => 'QuantityOnlyProduct', 'PriceDescription' => "\x{a3}1.41 each", 'UnitPrice' => '1.41', 'ImagePath' => 'http://img.tesco.com/Groce +ries/pi/118/5000175411118/IDShot_90x90.jpg', 'Price' => 1, 'BaseProductId' => '50043662', 'Name' => 'Oxo 12 Chicken Stock Cubes 71G' +, 'OfferValidity' => 'valid from 30/7/2012 u +ntil 9/9/2012', 'OfferLabelImagePath' => 'http://www.tesco +.com/Groceries/UIAssets/I/Sites/Retail/Superstore/Online/Product/pos/ +save.png' } ], 'TotalProductCount' => 1, 'PageNumber' => 0, 'TotalPageCount' => 1, 'StatusInfo' => 'Command Processed OK', 'PageProductCount' => 1

I am now looking at a few links to understand references. But to be honest I am not sure I understand what got returned. A Hash or an Array.


Comment on Re^8: Help with JSON Module
Download Code
Re^9: Help with JSON Module
by Corion (Pope) on Sep 08, 2012 at 10:15 UTC

      Thank you for your patience, but I'm just not understanding what I'm reading.

        The output of Data::Dumper is source code that would, when run through Perl, recreate the same data structure.

        As a series of exercises to familiarize yourself with walking down such a data structure, maybe the following helps you:

        1. What does print "$result" output, and what does that mean?
        2. Print the value of the TotalPageCount entry of $result .
        3. Assign the content of $result to a hash, %ex1, so that the (comma separated) output of keys %ex1 is (not necessarily in that order) StatusCode, Products, TotalProductCount, PageNumber, TotalPageCount, StatusInfo, PageProductCount . Hint: References Quick Reference
        4. What does print "$result->{Products}" output, and what does that mean? Why did the authors choose Products instead of Product as key name?
        5. Assign the content of $result->{Products} to an array, @ex2. Compare the output of print Dumper @ex2 and print Dumper \@ex2.
        6. Find a query that returns more than one product. Compare the output of your programs when run with that query.
        7. Descending through a data structure can be chained. Explain the following expressions: $result->{Products}->[0] and $result->{Products}->[0]->{ImagePath}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2014-10-23 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls