这是我使用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];
Run Code Online (Sandbox Code Playgroud)
记录的URL是正确的,但应用程序抛出异常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
我猜错误应该在上面的代码中,但我不明白为什么.欢迎任何帮助.
Tan*_* Vu 13
我认为你的代码是错误的.
NSURLRequest*request = [NSURLRequest requestWithURL:ms];
它应该改为:
NSURLRequest*request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];
| 归档时间: |
|
| 查看次数: |
3583 次 |
| 最近记录: |