打印值从JSON Response中形成一个数组内的stdObject

时间:2012-10-02 22:35:52

标签: php json object echo valuestack

我有点新的php和JSON,在挖掘了我无法找到的回复后,我希望你能帮助我...

我正在使用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

以及更多元素......但是行程数组内的任何对象都不会显示.. 我无法打印所显示的值,请帮助...

干杯

2 个答案:

答案 0 :(得分:2)

这是因为到达,离开和总计是对象本身。你必须做类似的事情:

 $output->Customer->FlightConfirmation->arrivalDate;
 $output->Customer->FlightConfirmation->departureDate
 $output->Customer->FlightConfirmation->RateInformation->RateDescription->ChargeableInfo->total;

答案 1 :(得分:0)

您错过了嵌套这些元素的级别在FlightConfirmation