我正在用JSONTouch执行JSON反序列化,但是它耗时太长,它阻塞了UI,所以我试图让一个GCD背景队列将序列化放到后台线程中。有时它运行良好,但有时我会在deserializeAsDictionary:weakSelf.mutableData error:&theError];
上获得EXC_BAD_ACCESS。在connectionDidFinishLoading中使用Grand Central Dispatch解析JSON:?
我不知道为什么。我已经使mutableData成为一个原子属性。我一次发出3个请求,所以我猜想它与线程尝试访问mutableData有关吗?或者可能mutableData在块运行时处于不良状态?
非常感谢!
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
__weak myViewController *weakSelf = self;
dispatch_queue_t updateQueue = dispatch_queue_create("parse json", NULL);
dispatch_async(updateQueue, ^{
NSError *theError = nil;
// This is the call that gives me EXC_BAD_ACCESS
NSDictionary *dict = [[CJSONDeserializer deserializer]
deserializeAsDictionary:weakSelf.mutableData error:&theError];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf setMutableData: nil];
});
});
dispatch_release(updateQueue);
}