在运行程序时报出编译错误

得到了一个编译错误:

Incompatible pointer to integer conversion sending 'void *' to parameter of type 
'NSJSONReadingOptions' (aka 'enum NSJSONReadingOptions') 

引起错误的block:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    //Incompatible pointer to integer conversion sending 'void *' to parameter of type 
    'NSJSONReadingOptions' (aka 'enum NSJSONReadingOptions')

    news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
    [mainTableView reloadData];
}

ChatGPT尝试为您解答,仅供参考
这个错误提示指出,在调用 NSJSONSerialization 的 JSONObjectWithData:options:error: 方法时,第二个参数 options 的类型与预期不符。


第二个参数 options 是一个枚举值,它指定了 JSON 序列化和反序列化时的行为选项。你传入的参数 nil 是一个 void * 类型的指针,而不是一个有效的 NSJSONReadingOptions 值。


要解决这个问题,你需要传入一个有效的 NSJSONReadingOptions 值。例如,你可以这样调用 JSONObjectWithData:options:error: 方法:

news = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

这样就可以避免类型转换错误的发生。