【发布时间】:2012-10-02 22:35:51
【问题描述】:
我对 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
还有更多元素……但是行程数组内对象下的任何内容都不会显示…… 我无法打印指示的这些值,请帮助...
干杯
【问题讨论】:
-
你也可以添加原始 JSON
-
试试
$output->Customer->FlightConfirmation->arrivalDate -
要清楚一点,你得到的是一个 PHP 对象,看起来它代表一个 JSON 响应,这与直接处理 JSON 略有不同
标签: php json object echo valuestack