0

这是我的解析代码:

    - (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; 
}

当我运行它时,它给了我这个:

2013-02-09 21:51:40.262 Places[7083:c07] -[__NSArrayI isEqualToString:]:无法识别的选择器发送到实例 0x8262b50 2013-02-09 21:51:40.263 Places[7083:c07] *由于应用程序终止未捕获的异常“NSInvalidArgumentException”,原因:“-[__NSArrayI isEqualToString:]:无法识别的选择器发送到实例 0x8262b50”

并强调这一点:

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

我的代码看起来很糟糕还是有人至少可以解释这个错误可能意味着什么?

这是我正在使用的。http://pastebin.com/vv8ScBfZ

对不起,我对这一切都很陌生。

感谢您的任何提示!

4

1 回答 1

2

看起来 FlightStatus 是一个带有一个对象的数组(带有一堆键的字典)。由于它是一个数组,因此您必须先获取该对象,然后才能在其包含的字典上使用 valueForKey:。修复它的最简单方法是更改​​它:

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

对此:

NSDictionary *FlightStatus =  [[flighttrackjson objectForKey:@"flightStatuses"] lastObject];
于 2013-02-10T05:42:51.657 回答