connectionDidFinishLoading显示NSString * jsonString行中的错误

时间:2014-09-22 09:47:52

标签: iphone

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSError *error = nil;
    NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0  error:&error] description];

    dispatch_async(dispatch_get_main_queue(), ^{

        if (!error)
        {
            self.textField.text = jsonString;
        }
        else
        {
            self.textField.text = [error localizedDescription];
        }

        [self.spinner stopAnimating];
        [self.fetchButton setEnabled:YES];
        self.connection = nil;
        self.buffer     = nil;
    });

});

}

当我编写此方法时,它会在第五行显示错误。请帮助我,我是Iphone的新手。谢谢。

2 个答案:

答案 0 :(得分:1)

你应该这样写:

NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0 error:&error] description];

答案 1 :(得分:0)

删除amp;

NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0  error:&error] description];

应该是

NSString *jsonString = [[NSJSONSerialization JSONObjectWithData:_buffer options:0  error:&error] description];