0

我对 php 和 JSON 有点陌生,在四处寻找回应后我找不到一个,我希望你能帮助我……</p>

我正在处理带有 JSON 响应的报告 JSON 响应看起来有点像这样:

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

我建立一个像这样的报告..

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

以及更多元素……但是在行程数组内的对象下的任何内容都不会显示……我无法打印指示的这些值,请帮助……</p>

干杯

4

2 回答 2

2

那是因为到达、离开和总计本身就是对象。您必须执行以下操作:

 $output->Customer->FlightConfirmation->arrivalDate;
 $output->Customer->FlightConfirmation->departureDate
 $output->Customer->FlightConfirmation->RateInformation->RateDescription->ChargeableInfo->total;
于 2012-10-02T22:41:03.203 回答
0

您缺少嵌套这些元素的级别在里面FlightConfirmation

于 2012-10-02T22:41:16.883 回答