JSON 응답에서 배열 내부의 STD 객체에서 값 인쇄
-
12-12-2019 - |
문제
Im Kinda는 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
.
및 더 많은 요소 ...하지만 드 일정 배열 내부의 물체 아래에있는 모든 것이 표시되지 않습니다 .. 표시된 것의 값을 인쇄 할 수 없으므로 도움을주십시오 ...
환호
해결책
도착, 출발 및 합계가 물체 자체이기 때문입니다.당신은 다음과 같은 일을해야합니다 :
$output->Customer->FlightConfirmation->arrivalDate;
$output->Customer->FlightConfirmation->departureDate
$output->Customer->FlightConfirmation->RateInformation->RateDescription->ChargeableInfo->total;
. 다른 팁
누락 된 레벨의 중첩 레벨은 FlightConfirmation
내부입니다.
제휴하지 않습니다 StackOverflow