I have this situation where I need to make a URL with a string that contains “.
For instance:
NSString *myStringWithURL = [NSString stringWithFormat:
@"http://myurl.com/setParam.php?setName=
{\"name\":\"%@\"} ", name];
// myStringWithURL will return the desired URL but it is a String.
// of course I need it as URL in order to make the request.
NSURL *targetURL = [NSURL URLWithString : myStringWithURL];
//This will return nil.
So the question is how to get my URL to not return nil?
The part {“name”:”My Name”} should be a JSON but this seemed simpler than using a NSDictionary and then using the parser of JSON and so on.
I thank you very much for your help!!
use stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding to convert your string