我正在使用 JSONTouch 执行 JSON 反序列化,但是它花费的时间太长并且它阻塞了 UI,所以我尝试制作一个 GCD 后台队列以将序列化放在后台线程中。有时它运行良好,但有时我得到一个 EXC_BAD_ACCESS on deserializeAsDictionary:weakSelf.mutableData error:&theError];
。
我不知道为什么。我已将 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);
}