- (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的新手。谢谢。
答案 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];