Someone knows why I'm getting null in this code?
NSURLRequest *requisicao = [NSURLRequest requestWithURL:
[NSURL URLWithString:URLAddress]];
When I debug this line and preview the content of this variable, I receive null -
"<NSURLRequest (null)>"
My URLAd开发者_开发百科dress is a request for a JSON service.
It's most likely null because URLAddress contains characters that need to be percent-escaped (which is what the URLWithString method needs).
Try using stringByAddingPercentEscapesUsingEncoding
:
NSURLRequest *requisicao = [NSURLRequest requestWithURL:
[NSURL URLWithString:
[URLAddress stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding]]];
However, see this answer by Dave DeLong which points out limitations of stringByAddingPercentEscapesUsingEncoding
and alternatives to it.
精彩评论