2014-09-30 45 views
-1

我想从数据库中检索html数据。我用这个代码解析,在iOS中解析HTML

-(NSString *)MultipleCharactersHTML:(NSString *)url 
{ 
NSMutableURLRequest *request =[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:url]]; 
NSData *returnData = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ]; 

NSString *returnString = [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding]; 
// NSLog(@"return string %@",returnString); 
returnString=[returnString stringByReplacingOccurrencesOfString:@"\\" withString:@""]; 
returnString=[returnString stringByReplacingOccurrencesOfString:@"\"<" withString:@"<"]; 
returnString=[returnString stringByReplacingOccurrencesOfString:@">\"" withString:@">"]; 
NSError *err = nil; 
// NSLog(@"return string replaced %@",returnString); 

// NSMutableArray *search = [NSJSONSerialization JSONObjectWithData:[returnString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&err]; 
// NSLog(@"search response %@",search); 
return returnString; 
} 

但我无法检索数据...

我要设置这个数据作为htmlstring我的WebView ...任何人都请指导我..从数据库

数据将在这个格式...

<div class="layout-content-row content-header " style="display: inline-block; margin: 36px 0px 23px; height: 30px; padding: 0px 0px 10px; color: rgb(34, 34, 34); font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px; background-color: rgb(249, 249, 249);"><div class="layout-content-col span-9" style="float: left; margin-left: 0px; width: 520px; height: 1px;"><h1 itemprop="name" style="color: rgb(51, 51, 51); font-size: 34px; margin-top: 0px; margin-bottom: 0px; padding: 0px; line-height: 30px; width: 700px;">Creative Vision</h1></div><div class="paging-links layout-content-col span-4" itemscope="" itemtype="http://schema.org/SiteNavigationElement" style="float: left; margin-left: 20px; position: relative; height: 30px; width: 220px;"><a href="http://developer.android.com/design/index.html" class="prev-page-link" zh-tw-lang="&#19978;&#19968;&#22530;&#35506;" zh-cn-lang="&#19978;&#19968;&#35838;" ru-lang="&#1055;&#1088;&#1077;&#1076;&#1099;&#1076;&#1091;&#1097;&#1080;&#1081;" ko-lang="&#51060;&#51204;" ja-lang="&#21069;&#12408;" es-lang="Anterior" style="position: absolute; color: rgb(37, 138, 175); text-transform: uppercase; left: -15px;">PREVIOUS</a><a href="http://developer.android.com/design/get-started/principles.html" class="next-page-link" zh-tw-lang="&#19979;&#19968;&#22530;&#35506;" zh-cn-lang="&#19979;&#19968;&#35838;" ru-lang="&#1057;&#1083;&#1077;&#1076;&#1091;&#1102;&#1097;&#1080;&#1081;" ko-lang="&#45796;&#51020;" ja-lang="&#27425;&#12408;" es-lang="Siguiente" style="position: absolute; color: rgb(37, 138, 175); text-transform: uppercase; right: 0px;">NEXT</a></div></div><span style="color: rgb(34, 34, 34); font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px; background-color: rgb(249, 249, 249);"></span><div id="jd-content" style="height: 790px; color: rgb(34, 34, 34); font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px; background-color: rgb(249, 249, 249);"><div class="jd-descr" itemprop="articleBody" style="height: 725px;"><img src="http://developer.android.com/design/media/creative_vision_main.png" style="max-width: 100%; margin-bottom: 15px;"><div class="vspace size-1" style="height: 10px;"> </div><p itemprop="description" style="margin-bottom: 15px;">Starting with Ice Cream Sandwich, we focused the design of Android around these three overarching goals, which apply to our core apps as well as the system at large. As you work with Android, consider these goals.</p><div class="vspace size-1" style="height: 10px;"> </div><div class="layout-content-row" style="display: inline-block; margin-bottom: 10px;"><div class="layout-content-col span-4" style="float: left; margin-left: 0px; width: 220px;"><h4 style="line-height: 21px; margin: 0px 0px 12px;">Enchant me</h4><p style="margin-bottom: 15px;">Beauty is more than skin deep. Android apps are sleek and aesthetically pleasing on multiple levels. Transitions are fast and clear; layout and typography are crisp and meaningful. App icons are works of art in their own right. Just like a well-made tool, your app should strive to combine beauty, simplicity and purpose to create a magical experience that is effortless and powerful.</p></div><div class="layout-content-col span-5" style="float: left; margin-left: 20px; width: 280px;"><h4 style="line-height: 21px; margin: 0px 0px 12px;">Simplify my life</h4><p style="margin-bottom: 15px;">Android apps make life easier and are easy to understand. When people use your app for the first time, they should intuitively grasp the most important features. The design work doesn't stop at the first use, though. Android apps remove ongoing chores like file management and syncing. Simple tasks never require complex procedures, and complex tasks are tailored to the human hand and mind. People of all ages and cultures feel firmly in control, and are never overwhelmed by too many choices or irrelevant flash.</p></div><div class="layout-content-col span-4" style="float: left; margin-left: 20px; width: 220px;"><h4 style="line-height: 21px; margin: 0px 0px 12px;">Make me amazing</h4><p style="margin-bottom: 15px;">It's not enough to make an app that is easy to use. Android apps empower people to try new things and to use apps in inventive new ways. Android lets people combine applications into new workflows through multitasking, notifications, and sharing across apps. At the same time, your app should feel personal, giving people access to superb technology with clarity and grace.</p></div></div></div><div class="content-footer layout-content-row" itemscope="" itemtype="http://schema.org/SiteNavigationElement" style="display: inline-block; margin-bottom: 10px; border-top-width: 1px; border-top-style: solid; border-top-color: rgb(204, 204, 204); margin-top: 10px; padding-top: 10px; width: 760px;"><div class="paging-links layout-content-col col-10" style="float: left; margin-left: 0px; position: relative; height: 30px; display: inline; margin-right: 10px; width: 580px;"><a href="http://developer.android.com/design/get-started/principles.html" class="next-page-link" zh-tw-lang="&#19979;&#19968;&#22530;&#35506;" zh-cn-lang="&#19979;&#19968;&#35838;" ru-lang="&#1057;&#1083;&#1077;&#1076;&#1091;&#1102;&#1097;&#1080;&#1081;" ko-lang="&#45796;&#51020;" ja-lang="&#27425;&#12408;" es-lang="Siguiente" style="position: absolute; color: rgb(37, 138, 175); text-transform: uppercase; right: 0px; left: 0px;">NEXT: DESIGN PRINCIPLES</a></div></div></div> 
+0

你能告诉我wats在我的文章中错了吗? – Tommy 2014-09-30 05:55:16

回答

1

是......作为Harshini Nerella说,你可以使用UIWebView直接从数据库加载标签。并确保以正确的格式将数据保存在数据库中。不要将检索到的值编码到PHP文件中。

1

如果您收到的htmlstring响应,那么你可以直接设置HTML字符串UIWebView实例。

UIWebView *eventInfoWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 130, self.view.frame.size.width, eventInfoSV.frame.size.height-130)]; 
[eventInfoWebView loadHTMLString:htmlString baseURL:nil]; 
+0

是多数民众赞成在我做了什么..但在这里htmlstring从数据库收到... – Tommy 2014-09-30 06:49:15

+0

NSData * returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];这一行不会将数据转换为字符串... – Tommy 2014-09-30 06:49:34