Response can be either Array or Object

If the departuresegment only returns one departure it will be of type object and the parsing to JSONArray will therefore throw an exception. Added a try catch statement around the parse to JSONArray and if an exception was thrown try to parse it o JSONObject instead