Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解析iphone中的html字符串_Iphone_Objective C - Fatal编程技术网

如何解析iphone中的html字符串

如何解析iphone中的html字符串,iphone,objective-c,Iphone,Objective C,我使用此代码从服务器发布和获取数据 NSString *post =[NSString stringWithFormat:@"any-data=%@", myData]; NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData leng

我使用此代码从服务器发布和获取数据

NSString *post =[NSString stringWithFormat:@"any-data=%@", myData];

NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://your-server.com/your-script.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Data: %@",data);
但问题是,当我在nslog中打印数据时,它是html格式的 如何在应用程序中检索实际结果

如何解析数据


如果有任何参考资料,请给我。

您可以随时尝试搜索1。大约,2

不幸的是,除非您能够保证格式良好的XHTML,否则尝试这样做并不容易。如果您的XHTML确实保证有效,那么您可以使用。您还可以查看
libxml/HTMLParser.h
中的
HTMLParser.h
代码,该代码由
libxml2
提供,其中可能会对您有所帮助


我注意到很多应用程序都使用基本的字符串拆分来提取数据。

如果您只是为了获取数据而删除HTML,
NSScanner
就可以了。如果要显示数据,UIWebView将起作用。这取决于您想对HTML做什么。您不需要XML解析器—在大多数情况下,这太过分了。

如果您觉得大胆,并且知道从文档中提取什么,请查看。显然,你必须找到与你搜索的内容完全匹配的正则表达式,并捕获你感兴趣的内容。

我在谷歌和stackoverflow上搜索了这个,但我找不到确切的解决方案,所以我问,我使用libxml2,但在这段代码中它需要html文件,但我有php文件,所以我如何使用HTMLPasser实现。如果您可以提供一些输入、一些所需的输出以及当前用于提取此信息的代码。它可以帮助人们给你建议。