This is my code to retrieve data from a MySQL table using JSON:
//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];
The URL logged is correct, but the app throws an exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance
I guess the error should be in the above code, but I don't see why. Any help is welcome.
I think your code is wrong.
NSURLRequest *request = [NSURLRequest requestWithURL:ms];
It should be change to:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With