尝试将NSString
传递给URLWithString
,但不会显示网址:
//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)
怎么了?
感谢
答案 0 :(得分:1)
<强> // //解决强>
这里是正确的代码,如果你们中的任何人使用我的相同的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]];