Objective c JSON解析时内存泄漏,

Objective c JSON解析时内存泄漏,,objective-c,memory-leaks,Objective C,Memory Leaks,当我试图解析JSON时,我在很多情况下都会面临内存泄漏。虽然它告诉SBJsonParser,但我知道这不会成为原因 - (id)JSONValue { SBJsonParser *jsonParser = [SBJsonParser new]; id repr = [jsonParser objectWithString:self]; // 100.0 % Memory Leak if (!repr) NSLog(@"-JSONValue failed.

当我试图解析JSON时,我在很多情况下都会面临内存泄漏。虽然它告诉SBJsonParser,但我知道这不会成为原因

- (id)JSONValue {
    SBJsonParser *jsonParser = [SBJsonParser new];
    id repr = [jsonParser objectWithString:self]; // 100.0 % Memory Leak
    if (!repr)
        NSLog(@"-JSONValue failed. Error is: %@", jsonParser.error);
    [jsonParser release];
    return repr;
}
而且内存泄漏也发生在

"id result=[JSON valueForKeyPath:@"result"]; " 
// 100.0% memory leak
id repr = [jsonParser objectWithString:self]; // 80.0% Memory Leak

我需要做什么来修复此>:(谢谢。

您应该改用此:

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];

您的代码是否在ARC下?很可能是泄漏(如果有泄漏的话)是因为您没有正确释放解析器本身或解析器返回的对象。这个答案是正确的。在我为客户端创建的项目中,SBJsonParser导致了一些非常奇怪且难以追踪的内存泄漏。使用iOS提供的JSON解析逻辑修复了泄漏问题。使用NSJSONSerialization、 但是,我还是得到了很多信息:(id repr=[jsonParser objectWithString:self];你不应该再使用它了,当你从nsurlconnection或你使用的其他方法接收数据时,你应该直接使用那行代码来检索JSON.ho!当然,谢谢你!