gpt4 book ai didi

ios - 无法将 NSString 传递给 NSURL URLWithString

转载 作者:行者123 更新时间:2023-11-29 12:28:48 25 4
gpt4 key购买 nike

尝试将我的 NSString 传递给 URLWithString 但没有出现 url:

//here i get my url from my API and replacing tags
NSString *queryContent = [[[(webLinks)[@"content"] stringByReplacingOccurrencesOfString:@"&" withString:@"&"]
stringByReplacingOccurrencesOfString:@"<p>" withString:@""]
stringByReplacingOccurrencesOfString:@"</p>" withString:@""];
//here i get the full url
NSURL * url = [NSURL URLWithString:queryContent];

添加 NSLogs:

 NSLog(@"query:%@", queryContent);
NSLog(@"website:%@", url);

结果是这样的:

query:http://mywebsite.com
website:(null)

怎么了?

谢谢

最佳答案

//已解决//

这里是正确的代码,如果你们中有人使用我的 WordPress 相同系统 JSON API:

NSRange r;
NSString *queryUrl = [(webLinks)[@"content"] stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSString *website = queryUrl;
while ((r = [website rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
website = [website stringByReplacingCharactersInRange:r withString:@""];

NSURL * url = [NSURL URLWithString:website];
[webView loadRequest:[NSURLRequest requestWithURL:url]];

关于ios - 无法将 NSString 传递给 NSURL URLWithString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28342757/

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