Recently stumbling upon this amazing site, I find myself compelled to seek your assistance with a particular issue:
How do you go about accessing the fields within the nested JSON object labeled "flightLegs" from the main JSON object "flights"?
When it comes to retrieving JSON objects from an external API (in this case flightstats) using a GWT application, my preferred method is as follows:
Here's the JSON object (successfully retrieved via the api and verifiable on the homepage as well):
"flights": [
{
"departureAirportFsCode": "ZRH",
"arrivalAirportFsCode": "NRT",
"departureDateFrom": "2013-01-28",
"arrivalDateAdjustment": 1,
"departureTime": "13:00:00.000",
...
// other fields
...
"flightLegs": [
{
"departureAirportFsCode": "MUC",
"arrivalAirportFsCode": "NRT",
"departureTime": "13:00:00.000",
...
// more fields
}
]
For instance, I have successfully created Overlays for all the fields within the parent JSON object "flights" using the code snippet below:
public final native String getDepartureFromAirport() /*-{
return this.departureAirportFsCode;
}-*/;
However, I am facing difficulty in accessing the Flightnumber field within the "flightLegs" JSON object. My attempt using the following code snippet has not yielded the desired outcome:
public final native String getDepartureFromAirport() /*-{
return this.flightLegs.flightNumber;
}-*/;
Unfortunately, this approach only returns a null or empty object, as per the error message received. I am at a loss on how to properly access the inner JSON object.
Any assistance would be greatly appreciated! Thank you sincerely!