Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^4: Help with JSON Module

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

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

Thank you. However with the following code:

#!/usr/bin/perl use warnings; use strict; use WebService::Tesco::API; use JSON; use Data::Dumper my $tesco = WebService::Tesco::API->new( app_key => 'xxxxx', developer +_key => 'xxxx', debug => 1, ); my $result = $tesco->login({ email => '', password => + 'xxxxx', }); print "Scan Item...."; my $pn = <>; #Scan Bar Code chop ($pn); # +remove %OA from end of scan code my $code = $tesco->product_search({ searchtext => $pn, extendedinfo => + 'N' }); print Dumper ($code);

All I get is:

"WebService::Tesco::API=HASH(0xf66940)" is not exported by the Data::D +umper module Can't continue after import errors at line 9. BEGIN failed--compilation aborted at line 9.

Replies are listed 'Best First'.
Re^5: Help with JSON Module
by Corion (Pope) on Sep 08, 2012 at 09:07 UTC

    You are missing a semicolon after use Data::Dumper.

    The correct line should be

    use Data::Dumper; # ^ Note the added semicolon here

      Thank you. (How many times do I have to make that mistake.) Now I get

      $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' => ' +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 +save.png' } ], 'TotalProductCount' => 1, 'PageNumber' => 0, 'TotalPageCount' => 1, 'StatusInfo' => 'Command Processed OK', 'PageProductCount' => 1 };

      Can you help with how to go on with the JSON decode statement?

      my $code = $tesco->product_search({ searchtext => $pn, extendedinfo => + 'N' });

      I am looking to create a variable that holds the value of "254881114" in this instance from ProductId.

      Best wishes - James.

        "Can you help with how to go on with the JSON decode statement?"

        I'm rather at a loss as to why you want to use JSON and what you want to decode.

        You've just demonstated that $tesco->product_search(...) returns Perl data (as a hashref) not JSON data.

        In your OP, you showed that you knew how to navigate through the data structure to get to the value you wanted:


        It seems to me that all you need is:

        my $data = $tesco->product_search(...); my $prod_id = $data->{Products}[0]{ProductId};

        -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992450]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-01-19 00:47 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.