标签:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIWebView *webview = [[UIWebView alloc] initWithFrame:self.view.bounds]; // [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.baidu.com"]]]; [self.view addSubview:webview]; AFHTTPRequestOperationManager *manger = [AFHTTPRequestOperationManager manager]; [manger GET:@"http://c.m.163.com/nc/article/AJHTO5LD00011229/full.html" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSDictionary *dict = (NSDictionary *)responseObject; NSString *body = [dict valueForKeyPath:@"AJHTO5LD00011229.body"]; NSArray *imgs = [dict valueForKeyPath:@"AJHTO5LD00011229.img"]; for (NSDictionary *img in imgs) { NSString *url = img[@"src"]; NSString *ref = img[@"ref"]; NSString *imgItem = [NSString stringWithFormat:@"<img src=‘%@‘ width=‘300px‘ >",url]; body =[body stringByReplacingOccurrencesOfString:ref withString:imgItem]; } NSArray *videos = [dict valueForKeyPath:@"AJHTO5LD00011229.video"]; for (NSDictionary *video in videos) { NSString *url = video[@"url_mp4"]; NSString *ref = video[@"ref"]; NSString *imgItem = [NSString stringWithFormat:@"<video width=‘300‘ height=auto controls=‘controls‘ autoplay=‘autoplay‘><source src=‘%@‘ type=‘video/mp4‘ /></video>",url]; body =[body stringByReplacingOccurrencesOfString:ref withString:imgItem]; } [webview loadHTMLString:body baseURL:nil]; NSLog(@"%@",dict.description); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; }
标签:
原文地址:http://www.cnblogs.com/coder-mh/p/4790991.html