0

这是我的标题部分:

@interface RootViewController : UIViewController
{
    NSString *status_id;
}

在控制器文件中,我正在分配变量:

- (void)updateStatus
{
    NSURL *url = [NSURL URLWithString:@"http://localhost/RightNow/API/status.json"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    NSError *error = [request error];
    NSString *response = [NSString alloc];

    NSError *error2;
    NSData* data = [response dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data      options:kNilOptions error:&error2];
    status_id = [json objectForKey:@"id"];
}

现在,当我再次尝试使用 status_id 时,我得到了错误

- (IBAction)likeClick:(id)sender
{
    NSURL *url = [NSURL URLWithString:@"http://localhost/RightNow/API/vote"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"POST"];
    [request setPostValue:status_id forKey:@"id"]; //The error comes here
    [request setPostValue:@"like" forKey:@"vote"];
    [request startSynchronous];
}

对不起我的英语不好。请帮助我,谢谢!

4

1 回答 1

1

[json objectForKey:@"id"]; 将返回自动释放池中的对象。您要么需要向它发送复制消息,例如

status_id = [[json objectForKey:@"id"] copy];

并在适当的时候释放它(如果不使用 ARC)

于 2012-09-10T19:10:35.523 回答