0

my aim is to develop a custom search based on goeuro.com(overview) in my spare time.

I simplyfied the search parameters to the minimum.

For example(you can try this, as loong as the search_id is valid):

http://www.goeuro.com/GoEuroAPI/rest/api/v5/results?&search_id=428558909

The search_id will be generated when you visit http://www.goeuro.com and enter the first time your search parameters.

This is the simplified data structure I generated from http://json2csharp.com/ using this as my input JSON:

{
  "serviceVersion": "v1.0.0",
  "sortVariants": null,
  "companies": {
    "1007": {
      "name": "Eurolines Germany",
      "logoUrl": "http://cdn-goeuro.com/static_content/web/logos/{size}/eurolines_germany.png",
      "id": "1007"
    }
  },
  "outbounds": {
    "3624107261930718525-38-flight-1-27": {
      "companyId": "38",
      "mode": "flight",
      "duration": "873",
      "outboundId": "3624107261930718525",
      "journeyId": "27",
      "departureTime": "2017-01-15T19:12:00.000+01:00",
      "arrivalTime": "2017-01-16T09:45:00.000+01:00",
      "stops": "1",
      "price": 16209,
      "updatedAt": "1",
      "segments": [ 1344486303, 574447503, 689435565, 833161604 ],
      "arrivalOvernightOffset": 1,
      "overnightOffset": 1
    }
  },
  "query": {
    "roundTrip": false,
    "airportToAirport": false,
    "locationsOutsideEurope": false,
    "searchId": "428558909",
    "departurePosition": "377001",
    "arrivalPosition": "398532",
    "departureDate": "2017-01-15T00:00:00.000+01:00",
    "passengers": {
      "adults": 1,
      "children": 0,
      "infants": 0
    },
    "userInfo": {
      "userLocale": "en",
      "userCurrency": "EUR"
    },
    "searchModes": {
      "bus": {
        "status": "done",
        "resultsQty": 13,
        "filteredResultsQty": 13
      },
      "flight": {
        "status": "done",
        "resultsQty": 276,
        "filteredResultsQty": 276
      },
      "train": {
        "status": "done",
        "resultsQty": 4,
        "filteredResultsQty": 4
      }
    }
  },
  "itineraries": [
    { "outboundLegId": "3624107261930718525-38-flight-1-27" }
  ],
  "segmentDetails": {
    "1002857016": {
      "type": "flight",
      "departureTime": "2017-01-16T08:35:00.000+01:00",
      "arrivalTime": "2017-01-16T12:05:00.000+02:00",
      "departurePosition": "313870",
      "arrivalPosition": "314920",
      "duration": "150",
      "company": "190",
      "transportId": "ca6199",
      "direction": "OUTBOUND",
      "overnightOffset": 1,
      "departureOvernightOffset": 1,
      "arrivalOvernightOffset": 1
    }
  },
  "positions": {
    "2091737": {
      "positionType": "busstation",
      "name": "Warszawa, Warszawa Centralny",
      "cityName": "Warsaw",
      "latitude": 52.22782,
      "longitude": 21.00224
    }
  },
  "currencies": {
    "EUR": {
      "name": "Euro",
      "symbol": "€"
    }
  }
}

The result from http://json2csharp.com/ is pretty good, but on the other side it generates something like this

public class Outbounds
    {
        public __invalid_type__362410726193071852538Flight127   __invalid_name__3624107261930718525-38-flight-1-27 { get; set; }
    }

I see two problems here:

  1. using __invalid_name__3624107261930718525-38-flight-1-27 is not a valid identifier in c#
  2. and the above mentioned name is some random name, which I can not rely on my data structure.

So, my actually questions are: How can I handle the request ? How shall the data structure look like ?

By the way this is the code I am using(plus the generated results from http://json2csharp.com/):

static void Main()
    {
        var client = new RestClient("https://www.goeuro.com");
        var request = new RestRequest("/GoEuroAPI/rest/api/v5/results?&search_id=428558909", Method.GET);
        request.RequestFormat = DataFormat.Json;
        // contentType: "application/json; charset=utf-8",
        var response = client.Execute<Response>(request).Data;

    }

Actually I found an existing solution(partly) for my problem: https://github.com/evgenTraytyak/goeuro-api , which is actually written in node.js, but I need c#, but by the way this example does not quite work(only if you have an existing search_id) and at the end I want to get the search_id from goeuro, without manually type it to my code. Maybe the reason that using this is that the JSON-Format changed...

99999
  • 141
  • 7
  • mmh, what could it be ... – 99999 Jan 14 '17 at 14:49
  • For `"outbounds"` use a `Dictionary` along the line of [Create a strongly typed c# object from json object with ID as the name](http://stackoverflow.com/a/34213724/3744182). Do something similar for `"segmentDetails"`, `"positions"`, `"EUR"` and so on. – dbc Jan 15 '17 at 07:50

0 Answers0