FlightAware Discussions

FlightXML3, FlightInfoStatus, json-error

In my php project, I’m trying to acces some flight data. Retrieving data is no problem as I can verify by using print_r($result). But I am not able to refer to the data afterwards.
I am trying to convert data to php by using json_decode, and then I get the errormsg: “json_decode() expects parameter 1 to be string”. Then I tried using json_decode($result->content, true) … no errormsg from json, but then I get "Invalid argument supplied for foreach()"

Any good suggestions?

My code is as follows:

$options = array(
‘trace’ => true,
‘exceptions’ => 0,
‘login’ => ‘xxx’,
‘password’ => ‘xxxxxxxx…’,

$client = new SoapClient(‘https://flightxml.flightaware.com/soap/FlightXML3/wsdl’, $options);
$params = array(“ident” => “SAS935”,0,"",2,0);
$result = $client->FlightInfoStatus ($params);

$flightArray = json_decode($result, true);
foreach ($flightArray[‘FlightInfoStatusResult’][‘flights’] as $flight) {
$result[‘ident’] = $flightArray[‘ident’];
$result[‘faFlightID’] = $flight[‘faFlightID’];
$result[‘origin’] = $flight[‘origin’][‘code’];
$result[‘origin_name’] = $flight[‘origin’][‘airport_name’];
$result[‘waypoints’] = getFlightRoute($flight[‘faFlightID’]);

The SOAP interface will not return JSON format data. We’ve got a small example of parsing data returned form the SOAP interface here on Github.

If you’d like to work with JSON formatted response data please try using the RESTful interface. We’ve also got some PHP examples for this style too.

Thanks for your fast reply :slight_smile: It is greatly appreciated.

When I try to use the SOAP coding example on the WeatherConditions from your link til Github, it works fine, but when I change the WeatherConditions-part to FlightInfoStatus-part, I still get get " Invalid argument supplied for foreach()"

Example code: foreach ($result->WeatherConditionsResult->conditions as $key => $condition) {
My code: foreach ($result->FlightInfoStatusResults->tailnumber as $key => $tailnumber) {

Perhaps because the FlightInfo-struct is more complex?
Is there a code example on the FlightInfo that works somewhere out there?

The FlightInfoStatusResult will contain an array of flight objects (FlightInfoStatusStruct()) that may contain an optionally present tail value. Printing all the tails in a result may look like this:

foreach($result->FlightInfoStatusResult->flights as $key => $flight) {

Wow, great - thanks alot, now it works. :grinning: