***************
#import "HMViewController.h"@interfaceHmviewcontroller ()@end@implementationHmviewcontroller- (void) viewdidload{[Super Viewdidload]; //1.url// http://c.m.163.com/nc/article/A7A94MCL00963VRO/full.htmlNsurl *url = [Nsurl urlwithstring:@"http://c.m.163.com/nc/article/A7AQOT560001124J/full.html"]; //2.requetsNsurlrequest *request =[Nsurlrequest Requestwithurl:url]; //3. Sending the request[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) {Nsdictionary*dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves Error:nil]; Nsdictionary*news = dict[@"a7aqot560001124j"]; [Self shownews:news]; }];}- (void) Shownews: (Nsdictionary *) news{//1. Remove Web contentNSString *body = news[@"Body"]; //2. Remove the imageNsdictionary *img = [news[@"img"] Lastobject]; NSString*imghtml = [NSString stringWithFormat:@""%@\"width=\ "300\" height=\ "171\" >", img[@"src"]]; //2. Create a webview to display the Web pageUIWebView *webview =[[UIWebView alloc] init]; Webview.frame=Self.view.bounds; [Self.view Addsubview:webview]; //3. Splicing Web contentNSString *html = [Body stringbyreplacingoccurrencesofstring:img[@"ref"] withstring:imghtml]; //4. Remove News HeadlinesNSString *title = news[@"title"]; //5. Time to take out newsNSString *time = news[@"Ptime"]; //Head ContentNSString *header = [NSString stringWithFormat:@"<div class=\"Title\">%@</div><div class=\ "time\" >%@</div>", title, Time]; HTML= [NSString stringWithFormat:@"%@%@", header, HTML]; //links to CSS files in MainbundleNsurl *cssurl = [[NSBundle mainbundle] Urlforresource:@"News"Withextension:@"CSS"]; HTML= [NSString stringWithFormat:@"%@<link rel=\"Stylesheet\"href=\ "%@\" >", HTML, Cssurl]; //5. Loading Web content[WebView loadhtmlstring:html baseurl:nil];}@end
iOS network Seventh day WebView-04 Imitation NetEase news Details