0

Im kinda new with php and JSON, and after digging around for a response I was not able to find one, I was hoping if you could help me…

I am working on a Report from with a JSON Response The JSON response looks somewhat like this:

stdClass Object
(
[FlightInformation] => stdClass Object
    (
   [@size] => 10
     [Itinerary] => Array
       (
         [0] => stdClass Object
           (
            [bookingID] => 123456789
            [creationDate] => 10/04/2012
            [Customer] => stdClass Object
               (
                [email] => someone@aol.com
               )
               [FlightConfirmation] => stdClass Object
                  (
                    [supplierId] => AA
                    [arrivalDate] => 10/04/2012
                    [departureDate] => 10/05/2012
                    [confirmationNumber] => 0987654321
                    [RateInformation] => stdClass Object
                  (
                    [@size] => 1
                    [RateDescription] => stdClass Object
                        (
                         [@promo] => false
                         [ChargeableInfo] => stdClass Object
                             (
                              [@total] => 57.94

I building a Report that is like this..

foreach( $response->FlightInformation->Itinerary as $output) {

    echo $output-> bookingID;
    echo $output-> creationDate;
    echo $output-> arrivalDate;         <<<< won't Print
    echo $output->departureDate;    <<<< won't Print
    echo $output->total;            <<<< won't Print

and some more elements… but anything that is under an object inside de Itinerary Array won't show.. I cannot get to print thes values indicated, please help…

Cheers

2 Answers2

2

That is because arrival, departure and total are objects themselves. You would have to do something like:

 $output->Customer->FlightConfirmation->arrivalDate;
 $output->Customer->FlightConfirmation->departureDate
 $output->Customer->FlightConfirmation->RateInformation->RateDescription->ChargeableInfo->total;
TheMethod
  • 2,893
  • 9
  • 41
  • 72
  • Thank you! it works! now I only have a problem which is, some how the Response comes with an @ on results... like total is @total... dont know what that is. – alejandrovg Oct 04 '12 at 16:39
  • Hi, if you are getting that data from a web service or something that you can't control that just may be the way the data defined. Are you having an issue trying to access any of the values preceded with an @ symbol? – TheMethod Oct 05 '12 at 11:43
0

Your missing a level of nesting those elements are inside FlightConfirmation:

prodigitalson
  • 60,050
  • 10
  • 100
  • 114