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

And there's your problem identified.

JSON's decode method has this syntax:

$perl_scalar = $json->decode($json_text)

but you're invoking it as:

$perl_scalar = $json->decode($hash_reference)

Use Data::Dumper to determine what data the hash reference points to. Perhaps your JSON string is in there somewhere.

-- Ken

Replies are listed 'Best First'.
Re^4: Help with JSON Module
by foggy3657 (Novice) on Sep 08, 2012 at 08:51 UTC

    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 => 'xxxxx@yahoo.co.uk', 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 tesco_json_dumper.pl line 9. BEGIN failed--compilation aborted at tesco_json_dumper.pl line 9.

      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' => '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 };

        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.