2011-07-18 15 views
2

誰かがなぜこのコードでnullになっているのか知っていますか?NSURLRequest nullを返します

NSURLRequest *requisicao = [NSURLRequest requestWithURL: 
           [NSURL URLWithString:URLAddress]]; 

私はこの行をデバッグすると、この変数の内容をプレビューすると、私はヌルを受け取る -
"<NSURLRequest (null)>"

私URLAddressはJSONサービスの要求です。

答えて

6

URLAddressには、パーセントエスケープする必要がある文字(URLWithStringメソッドに必要な文字)が含まれている可能性があります。

stringByAddingPercentEscapesUsingEncodingを使用してみてください:

NSURLRequest *requisicao = [NSURLRequest requestWithURL: 
    [NSURL URLWithString: 
     [URLAddress stringByAddingPercentEscapesUsingEncoding: 
         NSUTF8StringEncoding]]];  

しかし、stringByAddingPercentEscapesUsingEncodingおよびそれに代わるの限界を指摘したthis answer by Dave DeLongを参照してください。

関連する問題