NSString* path = @"http://username:apicode@flightxml.flightaware.com/json/FlightXML2/AirlineFlightSchedules?startDate=1394424000&endDate=1394486000&origin=KLAX&destination=KJFK&airline=UAL&howMany=10&offset=0";
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSMutableDictionary* json = nil;
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
else
{
NSMutableDictionary *routeRes;
routeRes = [json objectForKey:@"AirlineFlightSchedulesResult"];
NSMutableArray *res;
res = [routeRes objectForKey:@"data"];
for(NSMutableDictionary *flight in res)
{
NSLog(@"ident is %@, aircrafttype is %@, originName is %@, origin is %@,%@,%@,%@,%@,%@,%@,%@", [flight objectForKey:@"actual_ident"], [flight objectForKey:@"aircrafttype"], [flight objectForKey:@"arrivaltime"], [flight objectForKey:@"departuretime"], [flight objectForKey:@"destination"], [flight objectForKey:@"ident"], [flight objectForKey:@"meal_service"], [flight objectForKey:@"origin"], [flight objectForKey:@"seats_cabin_business"], [flight objectForKey:@"seats_cabin_coach"], [flight objectForKey:@"seats_cabin_first"]);
}
}
_connectionData = nil;
NSLog(@"connection nil");
}
}
}
I get data on flights from an external api, but how do I get the returned flights in an NSMutable Dictionary to write on tableview cells? I would like each flight returned to become its own tableview cell. Any help is appreciated.