검색된 json 배열에서 값을 반환합니다. 나는 일부 데이터가 아닌 다른 사람을 구문 분석 할 수 있습니다, 울부 짖는 소리는 데이터 메신저의보기 내려고입니다 :php cURL undefined index
코드 :
<?php
$headers = array(//Set headers data
'Content-Type:application/json',
'Authorization: Basic '. base64_encode("Username removed:Password removed") //Set basic authentication
);
$today = date('Y/m/d');
$serviceUid='W96397';
$ch = curl_init('https://api.rtt.io/api/v1/json/service/'.$serviceUid.'/'.$today);//serviceUid is set here
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_ENCODING, ""); //Set gzip decoding
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //not sure
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //Set headers in curl options, set previously
$result=curl_exec($ch); //Execute and retrive data
curl_close($ch);
$result_arr = json_decode($result, true);
$serviceUid= $result_arr['serviceUid']; //works fine
$runningIdentity = $result_arr['runningIdentity']; //works fine
//All commented out bellow do not return any data*********
foreach($result_arr['locations'] as $locations){
$crs = $locations['crs'];
// $gbttBookedDeparture = $locations['gettBookedDeparture'];
$isCall = $locations['isCall'];
$isPublicCall = $locations['isPublicCall'];
// $realtimeDeparture = $locations['realtimeDeparture'];
// $realtimeDepartureActual = $locations['realtimeDepartureActual'];
// $platform = $locations['platform'];
// $platformConfirmed = $locations['platformConfirmed'];
// $platformChanged = $locations['platformChanged'];
$displayAs = $locations['displayAs'];
}
?>
오류는 다음과 같습니다 PHP 공지 : 정의되지 않은 인덱스 : 플랫폼 데이터 FL 따르면 pastebin.com/raw.php?i=P5A7s1Ur
왜 오류 행 번호가 무엇인가 말을하지 않습니다? '$ anyArr [ 'platform']'호출은 어디에 있습니까? 그 줄은 이제 코드에 주석 처리됩니다. $ locations [ 'platform'] : ''; ' – Alex
주석 처리 된 모든 행은 일치하지 않으면 오류가 발생합니다. – user3770935
가능한가? 더미의 한 레코드에이 값이 누락 되었습니까? – ethrbunny