尝试将我的 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/