使用 NSDate 时 NSURL 为零

发布于 2024-09-26 23:53:45 字数 534 浏览 2 评论 0原文

我有一个 NSURL,其中包含一个 URL 和一个 NSDate 变量:

NSURL *url = [[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.googlebio.com/xml_test.aspx?date=%@",self.storeDate]] autorelease];

我也尝试过这种方式,但无济于事:

NSString*string = [NSString stringWithFormat:@"http://www.googlebio.com/xml_test.aspx?date=%@",self.storeDate];

    NSURL*url=[NSURL URLWithString:string];
    [url autorelease];

应用程序不会崩溃,但当我调试它时,url 为零。

关于为什么会这样的任何想法吗?

谢谢。

斯特凡.

I have an NSURL which contains a URL and a variable that is an NSDate:

NSURL *url = [[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.googlebio.com/xml_test.aspx?date=%@",self.storeDate]] autorelease];

I also tried it this way but to no avail:

NSString*string = [NSString stringWithFormat:@"http://www.googlebio.com/xml_test.aspx?date=%@",self.storeDate];

    NSURL*url=[NSURL URLWithString:string];
    [url autorelease];

The application does not crash but when I debug it, url is nil.

Any ideas as to why this is?

Thanks.

Stefan.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面如桃花 2024-10-03 23:53:46

如果您的日期采用 NSURL 会混淆的格式,那么它将为零。确保对日期进行 urlencode,或以合法 URL 的方式表示它。看看这个:

[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

也许如果你把你的网址字符串的调试语句,我可以提供进一步的帮助

If your date is in a format that NSURL will be confused by, then it will be nil. Make sure you urlencode your date, or represent it in a way that is a legitimate URL. Look into this:

[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

Perhaps if you put a debug statement of your url string, I can help further

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文