in reply to Help with JSON Module

Please consider taking things step by step so that you build up to the solution incrementally rather than trying to take one giant leap at the start.

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); use JSON::PP; my $j = JSON::PP->new; my $d = $j->decode(<<'END'); { "StatusCode": 0, "StatusInfo": "Command Processed OK", "BranchNumber": "5528", "CustomerId": "20846164", "CustomerName": "Mr Stubbs", "SessionKey": "5VApkMMTjO8LtFCy9VjcSrcZKxoewwHGj6XoUUGaH2fBWf73cU", "InAmendOrderMode": "N", "BasketID": "98911496", "ChosenDeliverySlotInfo": "No delivery slot is reserved.", "CustomerForename": "James" } END pp($d)

Produces:

{ BasketID => 98911496, BranchNumber => 5528, ChosenDeliverySlotInfo => "No delivery slot is reserved.", CustomerForename => "James", CustomerId => 20846164, CustomerName => "Mr Stubbs", InAmendOrderMode => "N", SessionKey => "5VApkMMTjO8LtFCy9VjcSrcZKxoewwHGj6XoUUGaH +2fBWf73cU", StatusCode => 0, StatusInfo => "Command Processed OK", }

Replies are listed 'Best First'.
Re^2: Help with JSON Module
by foggy3657 (Novice) on Sep 07, 2012 at 16:04 UTC

    Sorry you have lost me. If I add (<<'END'). Then all of the code below changes colour and I'm going to assume it will not run.

    The last bit of code

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

    Returns:

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

    Apologies if I am appearing to be stupid.

      This works and returns the correct data "254881114". But I don't see how this helps with my program?

      #!/usr/bin/perl use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); use JSON::PP; my $j = JSON::PP->new; my $d = $j->decode(<<'END'); { "StatusCode": 0, "StatusInfo": "Command Processed OK", "PageNumber": 0, "TotalPageCount": 1, "TotalProductCount": 1, "PageProductCount": 1, "Products": [ { "BaseProductId": "50043662", "EANBarcode": "5000175411118", "CheaperAlternativeProductId": "", "HealthierAlternativeProductId": "", "ImagePath": "http://img.tesco.com/Groceries/pi/118/5000175411118/IDSh +ot_90x90.jpg", "MaximumPurchaseQuantity": 99, "Name": "Oxo 12 Chicken Stock Cubes 71G", "OfferPromotion": "Price Drop Was £1.13 Now £1.00 ", "OfferValidity": "valid from 30/7/2012 until 9/9/2012", "OfferLabelImagePath": "http://www.tesco.com/Groceries/UIAssets/I/Site +s/Retail/Superstore/Online/Product/pos/save.png", "Price": 1, "PriceDescription": "£1.41 each", "ProductId": "254881114", "ProductType": "QuantityOnlyProduct", "UnitPrice": 1.41, "UnitType": "100g" } ] } END pp($d); my $pid; $pid = $d->{Products}[0]{ProductId}."\n"; print $pid,"\n";