0
votes

Here is my parsing code:

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSError *myError = nil;
NSDictionary *flighttrackjson = [NSJSONSerialization JSONObjectWithData:jsonresponse options:NSJSONReadingMutableLeaves  error:&myError];
NSArray *FlightStatus =  [flighttrackjson objectForKey:@"flightStatuses"];
NSString *FlightID = [FlightStatus valueForKey:@"flightId"];
NSString *DepartACode = [FlightStatus valueForKey:@"departureAirportFsCode"];
NSString *ArivalACode = [FlightStatus valueForKey:@"arrivalAirportFsCode"];
NSArray *DepartATime = [FlightStatus valueForKey:@"departureDate"];
NSArray *AriveATime = [FlightStatus valueForKey:@"arrivalDate"];
NSString *DepartTimeString = [DepartATime valueForKey:@"dateLocal"];
NSString *ArriveTimeString = [AriveATime valueForKey:@"dateUtc"];
NSArray *Delays = [FlightStatus valueForKey:@"delays"];
NSString *DepartDelayMinutes = [Delays valueForKey:@"departureGateDelayMinutes"];
NSString *ArriveDelayMinutes = [Delays valueForKey:@"arrivalGateDelayMinutes"];
NSArray *AirportInfo = [FlightStatus valueForKey:@"airportResources"];
NSString *DepartTerminal = [AirportInfo valueForKey:@"departureTerminal"];
NSString *DepartAGate = [AirportInfo valueForKey:@"departureGate"];
NSString *ArriveTerminal = [AirportInfo valueForKey:@"arrivalTerminal"];
NSString *ArriveAGate = [AirportInfo valueForKey:@"arrivalGate"];
NSString *BaggageClaim = [AirportInfo valueForKey:@"baggage"];
flightID.text=FlightID;
DepartCode.text=DepartACode;
ArrivalCode.text=ArivalACode;
DepartTime.text=DepartTimeString;
ArriveTime.text=ArriveTimeString;
DepartDelay.text=DepartDelayMinutes;
ArriveDelay.text=ArriveDelayMinutes;
DepartTerm.text=DepartTerminal;
DepartGate.text=DepartAGate;
ArriveTerm.text=ArriveTerminal;
ArriveGate.text=ArriveAGate;
Baggage.text=BaggageClaim; 
}

When I run that, it gives me this:

2013-02-09 21:51:40.262 Places[7083:c07] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x8262b50 2013-02-09 21:51:40.263 Places[7083:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x8262b50'

And highlights this:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

Does my code look bad or can someone at least explain what this error might mean?

Here is what I'm working with. http://pastebin.com/vv8ScBfZ

I'm sorry I am very new to all this.

Thanks for any tips!

1
You should show us an excerpt from your JSON for us to help you diagnose this. But the above doesn't make sense, because you're telling us that FlightStatus is an NSArray, but then you're trying to retrieve individual NSString values from this array using valueForKey. If FlightStatus was an array of dictionaries, then valueForKey would return an array of values, not an individual NSString. And your error message would seem to confirm this, because it's telling you that you retrieved a NSArray at some point and you're trying to use it as a NSString.Rob
guessing from the error, I'm thinking that you may be mis-ordering some details about the JSON structure. You're saying it's a dictionary, the items within are arrays...but is that accurate? or is it an array of items, each of which is like a dictionary?Robot Woods
Here is what I'm working with, thanks by the way! pastebin.com/vv8ScBfZJon Sullivan

1 Answers

2
votes

It looks like FlightStatus is an array with one object (a dictionary with a bunch of keys). Since it's an array you have to get that one object first, before you can use valueForKey: on its contained dictionaries. The easiest way to fix it is to change this:

NSArray *FlightStatus =  [flighttrackjson objectForKey:@"flightStatuses"];

to this:

NSDictionary *FlightStatus =  [[flighttrackjson objectForKey:@"flightStatuses"] lastObject];