【问题标题】:NSCFString absoluteURL exceptionNSCFString absoluteURL 异常
【发布时间】:2014-02-24 01:51:29
【问题描述】:

这是我使用 JSON 从 MySQL 表中检索数据的代码:

//URL definition where php file is hosted

    int categoriaID = [[categoriaDescription objectForKey:@"idCategoria"] intValue];

    NSString *string = [NSString stringWithFormat:@"%d", categoriaID];
    NSLog(@"CATEGORIA ID STRING %@",string);
    NSMutableString *ms = [[NSMutableString alloc] initWithString:@"http://mujercanariasigloxxi.appgestion.eu/app_php_files/categoriaslist.php?id="];
    [ms appendString:string];
    // URL request
    NSLog(@"URL = %@",ms);
    NSURLRequest *request = [NSURLRequest requestWithURL:ms];
    //URL connection to the internet
    [[NSURLConnection alloc]initWithRequest:request delegate:self];

记录的 URL 正确,但应用程序抛出异常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 

我猜错误应该在上面的代码中,但我不明白为什么。欢迎任何帮助。

【问题讨论】:

    标签: ios nsurlrequest


    【解决方案1】:

    我认为你的代码是错误的。

    NSURLRequest *request = [NSURLRequest requestWithURL:ms];

    应该改为:

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多