我试图在我的IOS应用程序中下载HTML,一旦我将html加入我的应用程序,我想搜索下载的数据并在两个值之间打印文本。 示例:如果我从我的html数据中获取此数据: 内容 - 开始狗狗想要做的东西停止
我想在UITextView中在START和STOP之间打印文本,以便人们可以干净地查看文本。有没有办法做到这一点? 我到目前为止的代码:
@implementation FirstViewController
//http://www.streakadvice.com/path-to-the-stash-luke.html
- (void)viewDidLoad{
[super viewDidLoad];
if (myConnection == nil) {
myData = [NSMutableData new];
NSString *urlString = [NSString stringWithFormat:@"http://www.streakadvice.com/path-to-the-stash-luke.html"];
myConnection = [NSURLConnection connectionWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:urlString]]
delegate:self];
}
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"SFTCBR3.png"]]];
NSString *fullURL = @"http://www.streakadvice.com/path-to-the-stash-luke.html";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[myData appendData:data];
}
-(void)initializeVariablesAgain {
myData = nil;
myConnection = nil;
myTextView = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *stringToLookup = [[NSString alloc]initWithData:myData encoding:NSASCIIStringEncoding];
if ([stringToLookup rangeOfString:@"Start"].location != NSNotFound) {
myLabel.text = @" ";
} else {
myLabel.text = @" ";
}
myTextView.text = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
[self initializeVariablesAgain];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
JSON可能不是您正在寻找的格式 - 特别是因为它听起来只是想要一个基本的字符串替换。我可以推荐Get String Between Two Other Strings in ObjC吗?