我正在尝试使用 JSON 解析来自 yahoo Finance 的数据。由于某种原因,该应用程序不断崩溃。似乎最后一行代码导致了崩溃。当我注释掉该行时,不会发生崩溃。这是我到目前为止所拥有的......有什么想法吗?
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1
#define kLatestKivaLoansURL [NSURL URLWithString: @"http://query.yahooapis.com/v1/public/yql? q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)%0A%09%09&env =http%3A%2F%2Fdatatables.org%2Falltables.env&format=json"] //2
#import "JsonViewController.h"
@implementation JsonViewController
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
kLatestKivaLoansURL];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* latestLoans = [json objectForKey:@"query"]; //2
NSLog(@"query: %@", latestLoans); //3
NSDictionary* loan = [latestLoans objectAtIndex:0]; /////// Where crash happens //////
}
@end
这是控制台中的错误消息
[__NSCFDictionary objectAtIndex:]:无法识别的选择器发送到实例 0x6a65420 2012-07-15 01:18:29.492 Json[1730:f803] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFDictionary objectAtIndex:]:无法识别选择器发送到实例 0x6a65420'