Read the json files

Want to post something that doesn't quite fit into the other forums? This is the place for that.
Post Reply
Nevermind
Posts: 29
Joined: Thu Sep 11, 2014 12:36 am

Read the json files

Post by Nevermind » Sat Feb 20, 2016 8:27 pm

Hi,

when I try to read a (VRS) json file in PHP I always get NULL.
Json-File: http://82.75.94.67/VirtualRadar/ServerConfig.json

phpcode:

Code: Select all

<?php

$url = "http://82.75.94.67/VirtualRadar/ServerConfig.json";

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$vrs_data = json_decode($result);

var_dump($vrs_data);

?>
If I choose a JSON file from Dump1090 then it works.
For example: http://luftwache.devbot.de:8080/data/stats.json

Edit:
Looks strange.

Code: Select all

���`I�%&/m�{J�J��t��`$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N'���?\fdl��J�ɞ!���?~|?"~�Ggˢ-��iѴ�r�E~����⣑���yq1o��s����-��,��������y���/�wƟ�Ͽ�Vo�W��G��y�ˋ�>�ſ�G�y��~�hwD�e�:o���'_e��~���������m[�~|��nN�u�/��Քp��۳�<[����n���z�*�|fZ�7e�&��ƻw��v�w<�?�n��}���������O������WW���i[�s|;�#
�u��y���jA�=�WB���M���gS��i`{�`��޽�޿�`����O?}���ރ_��gQM�2��'٧�<��`H�'uuE@;{Orz�o���������a��UuQ������C�ˍ��;}Ô#�7�qQO���=^����̧m�[��&e>��a��褬��A���l�yu~ΝO��n�0��EI�C�|�����i�fE��\_�����Q����~��}t���Y���|v�?g�`�����3_���j�?�\~6�|�Pxu{�?W}��_�K~��;Wy>S���u��M*�)}@�_�D��&�$[�Z/_嫪nC��k��b�&���4��e�]�gE5��u���,�������/�2�_��j�l=Y��j����ٛb���_Ki��C-��Tʂo B��lF�y��/�ee�$@�b�x��S���|Z-g
l�G��i^�_�����0m�^���LЬ��5�i�_2�_?}��ǃo�o���/��	�������UU�y������e���I������
�ݻA��d�kBdm�o}���f:�g$�.����|�>#�
����=B��_d�[�"�$/�L�d��$��d������w?�%���m�

Any tips?

agw
Posts: 2249
Joined: Fri Feb 17, 2012 3:20 am

Re: Read the json files

Post by agw » Thu Feb 25, 2016 12:44 am

VRS supports gzip compression of the response. This page here shows how to decompress it:

http://stackoverflow.com/questions/2611 ... rl-and-php

Nevermind
Posts: 29
Joined: Thu Sep 11, 2014 12:36 am

Re: Read the json files

Post by Nevermind » Thu Feb 25, 2016 9:49 am

Merci :)

Nevermind
Posts: 29
Joined: Thu Sep 11, 2014 12:36 am

Re: Read the json files

Post by Nevermind » Thu Feb 25, 2016 1:55 pm

Next question :)

why sometimes the Key ["Mlat"] is not set in the Array?

["Mlat"] available

Code: Select all

[8]=>
    array(48) {
      ["Alt"]=>
      int(37000)
      ["AltT"]=>
      int(0)
      ["Bad"]=>
      bool(false)
      ["Call"]=>
      string(7) "SWR121B"
      ["CallSus"]=>
      bool(false)
      ["CMsgs"]=>
      int(453)
      ["CNum"]=>
      string(3) "701"
      ["Cou"]=>
      string(11) "Switzerland"
      ["Engines"]=>
      string(1) "2"
      ["EngMount"]=>
      int(0)
      ["EngType"]=>
      int(3)
      ["FlightsCount"]=>
      int(332)
      ["From"]=>
      string(28) "ENGM Oslo Gardermoen, Norway"
      ["FSeen"]=>
      string(26) "/Date(1456407016760+0000)/"
      ["Gnd"]=>
      bool(false)
      ["HasPic"]=>
      bool(false)
      ["HasSig"]=>
      bool(true)
      ["Help"]=>
      bool(false)
      ["Icao"]=>
      string(6) "4B161A"
      ["Id"]=>
      int(4920858)
      ["Interested"]=>
      bool(false)
      ["Lat"]=>
      float(53.369659)
      ["Long"]=>
      float(9.392997)
      ["Man"]=>
      string(6) "Airbus"
      ["Mdl"]=>
      string(15) "Airbus A320-214"
      ["Mil"]=>
      bool(false)
      ["Mlat"]=>
      bool(false)
      ["Op"]=>
      string(28) "Swiss International Airlines"
      ["OpIcao"]=>
      string(3) "SWR"
      ["PosTime"]=>
      float(1456407139592)
      ["Rcvr"]=>
      int(7)
      ["Reg"]=>
      string(6) "HB-IJQ"
      ["Sig"]=>
      int(29)
      ["Spd"]=>
      int(460)
      ["SpdTyp"]=>
      int(0)
      ["Species"]=>
      int(1)
      ["Sqk"]=>
      string(4) "0757"
      ["Tisb"]=>
      bool(false)
      ["To"]=>
      string(33) "LSZH Zürich, Zurich, Switzerland"
      ["Trak"]=>
      float(185.4)
      ["TrkH"]=>
      bool(false)
      ["Trt"]=>
      int(2)
      ["TSecs"]=>
      int(123)
      ["Type"]=>
      string(4) "A320"
      ["Vsi"]=>
      int(0)
      ["VsiT"]=>
      int(0)
      ["WTC"]=>
      int(2)
      ["Year"]=>
      string(4) "1997"
    }
["Mlat"] not available:

Code: Select all

    [0]=>
    array(35) {
      ["AltT"]=>
      int(0)
      ["Bad"]=>
      bool(false)
      ["CallSus"]=>
      bool(false)
      ["CMsgs"]=>
      int(1)
      ["CNum"]=>
      string(3) "116"
      ["Cou"]=>
      string(7) "Germany"
      ["Engines"]=>
      string(1) "2"
      ["EngMount"]=>
      int(0)
      ["EngType"]=>
      int(3)
      ["FlightsCount"]=>
      int(595)
      ["FSeen"]=>
      string(26) "/Date(1456407136291+0000)/"
      ["Gnd"]=>
      bool(false)
      ["HasPic"]=>
      bool(false)
      ["HasSig"]=>
      bool(false)
      ["Icao"]=>
      string(6) "3C6613"
      ["Id"]=>
      int(3958291)
      ["Interested"]=>
      bool(false)
      ["Man"]=>
      string(6) "Airbus"
      ["Mdl"]=>
      string(15) "Airbus A320-211"
      ["Mil"]=>
      bool(false)
      ["Op"]=>
      string(9) "Lufthansa"
      ["OpIcao"]=>
      string(3) "DLH"
      ["Rcvr"]=>
      int(8)
      ["Reg"]=>
      string(6) "D-AIPS"
      ["SpdTyp"]=>
      int(0)
      ["Species"]=>
      int(1)
      ["Sqk"]=>
      string(0) ""
      ["Tisb"]=>
      bool(false)
      ["TrkH"]=>
      bool(false)
      ["Trt"]=>
      int(1)
      ["TSecs"]=>
      int(3)
      ["Type"]=>
      string(4) "A320"
      ["VsiT"]=>
      int(0)
      ["WTC"]=>
      int(2)
      ["Year"]=>
      string(4) "1990"
    }
In my attempt I have, for example:
135 Planes total
16 of these are ["Mlat"]=> bool(true)
98 of these are ["Mlat"]=> bool(false)
makes 114

What about the remaining 21?

agw
Posts: 2249
Joined: Fri Feb 17, 2012 3:20 am

Re: Read the json files

Post by agw » Sun Feb 28, 2016 2:10 am

If the field is null in the aircraft list then it's not sent. Also if you're supplying a dataversion value in your request (I think it's the ldv query string parameter) then the MLAT field won't be sent if it hasn't changed since the last request.

It's not just the Mlat field that behaves that way, most of the fields for an aircraft are not sent if they're either null on the server or haven't changed since the last request (and if you're sending dataversion values with your request).

Post Reply