0

我收到错误

“不兼容的指针类型将'NSURL *'发送到'NSString *'类型的参数

打电话时initWithContentsOfFile:usedEncoding:error:

- (NSMutableArray *)qBlock{
    NSURL *url = [[NSURL alloc] initWithString:@"http://addressToPath.php"];
    NSError *error = nil;
    NSStringEncoding encoding;
    NSString *response = [[NSString alloc] initWithContentsOfFile:url 
                                                     usedEncoding:&encoding 
                                                            error:&error];
    const char *convert = [response UTF8String];
    NSString *responseString = [NSString stringWithUTF8String:convert];
    NSMutableArray *sample = [responseString JSONValue];


    return sample;

}
4

1 回答 1

3

initWithContentsOfFile:encoding:error:接收 aNSString *作为文件路径,而不是NSURL *. 您需要致电initWithContentsOfURL:encoding:error:

NSString *response = [[NSString alloc] initWithContentsOfURL:url 
                                             usedEncoding:&encoding 
                                                    error:&error];
于 2012-04-24T20:45:32.237 回答