这是我使用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
我猜错误应该在上面的代码中,但我不明白为什么。欢迎任何帮助。
答案 0 :(得分:13)
我认为你的代码错了。
NSURLRequest * request = [NSURLRequest requestWithURL:ms];
应该改为:
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];