从JSON加载属性,获取“发送到已释放实例的消息". [英] Loading properties from JSON, getting "message sent to deallocated instance"

查看:74
本文介绍了从JSON加载属性,获取“发送到已释放实例的消息".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我从Web服务加载我的自定义对象,并尝试将属性存储为NSString,但一直遇到此错误:

So I load my custom object from a web service and am trying to store the properties as NSStrings but keep running into this error:

-[CFString _cfTypeID]: message sent to deallocated instance 0x100d3d40
-[CFString retain]: message sent to deallocated instance 0x100d3d40

我启用了僵尸,但这并没有真正向我展示解决方案.

I enabled zombies, but that's not really showing me a solution.

我的属性定义为:

@property (strong, nonatomic) NSString *title;
@property (assign, nonatomic) NSString *ID;
@property (strong, nonatomic) NSString *redLabel;
@property (strong, nonatomic) NSString *greenLabel;

然后我创建对象的实例并调用网络服务

Then I create an instance of my object and call the webservice

QuickList *list = [[QuickList alloc] init];
[list loadLatestQuickList];

最后,在loadLatestQuickList ...

NSURLRequest *request = // create a GET request...
[NSURLConnection sendAsynchronousRequest:request queue:notMainQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
    NSError *parsingError;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&parsingError];
    if (!parsingError && [json isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dataDictionary = [json objectForKey:@"data"];
        NSDictionary *quickListDictionary = [dataDictionary objectForKey:@"QuickList"];

        NSString *ID = [quickListDictionary objectForKey:@"id"];
        NSString *title = [quickListDictionary objectForKey:@"name"];
        NSString *redLabel = [quickListDictionary objectForKey:@"red_label"];
        NSString *greenLabel = [quickListDictionary objectForKey:@"green_label"];

        self.ID = ID;
        self.title = title;
        self.redLabel = redLabel;
        self.greenLabel = greenLabel;

        // tell a channel that everything is loaded
    }
    else {
        NSLog(@"%@",parsingError);
    }
}];

现在,每当我尝试访问list.ID或其他某些属性时,都会出现已分配实例"错误.关于我为什么会收到此错误的任何想法?

Now whenever I try to access list.ID or some other property I get the "deallocated instance" error. Any thoughts as to why I'm getting this error?

推荐答案

您的ID属性也应为strong.

这篇关于从JSON加载属性,获取“发送到已释放实例的消息".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆