gpt4 book ai didi

ios - NSURL URLWithString 返回 nil

转载 作者:行者123 更新时间:2023-11-29 12:22:05 40 4
gpt4 key购买 nike

我被困在 NSURLURLWithString 的一个非常明显的方法中 我正在传递一个 string 并在创建 URL 它返回 nil,我的 string 是完美的。当我在浏览器中使用相同的字符串时,它工作正常。我正在使用以下方法将 NSString 转换为 NSURL:

NSURL *url = [NSURL URLWithString:urlString];
//urlString is my perfect string

我还尝试使用以下方法首先对我的字符串进行编码

NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// using this line my output string when I log url is "url%10%10%10%10%10%10..."

%10 成为我的 url 的后缀,重复次数超过 100 次。如果有人知道 %10 是什么或者可以做些什么来克服这个问题。

这是我的urlString:
comment says too many character but it is obvious that there are not much characters

最佳答案

使用下面的代码来解决您的问题。

NSString *str = msgDetail[@"thumbnail"];

NSString* webStringURL = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

NSURL* url = [NSURL URLWithString:webStringURL];

关于ios - NSURL URLWithString 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317156/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com