-
29-08-2013, 04:48 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Làm sao để convert HTML trong iOS ???
Hiện tại em muốn làm 1 app duyệt forum như kiểu tinhte, bắt tay vào tìm hiểu thì gặp vấn đề: dùng AFNetworking parse dữ liệu về JSON thì nó báo server ko trả về dữ liệu JSON mà chỉ là text/html ( do em ko phải người làm forum đó :'( ), giờ thì em nên làm thế nào đây ?
Mã:NSURL *url = [NSURL URLWithString:@"http://kites.vn/51-1/tv-series.html"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"JSON data: %@", JSON); } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject){ NSLog(@"Request failed with error: %@, %@",error,error.userInfo); NSLog(@"header field of response: %@", [response allHeaderFields]); }]; [operation start];
Mã:DemoAFNetworking[698:c07] Request failed with error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {( "text/json", "application/json", "text/javascript" )}, got text/html" UserInfo=0x767efb0 {NSLocalizedRecoverySuggestion=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.mes/fb#"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Kites-TV Series - We Fly</title>......
View more random threads:
- Tạo ảnh trong textview Iphone như thế nào?
- Sự kiện gì sảy ra trong xcode khi kéo các UIButton, UIlabel......
- Code thông dụng của lập trình IOS (Tiếng Việt)
- Lấy khoảng cách từ (camera)iphone xuống mặt đất, sử dụng GPS và CLLocationManager.
- Cách đọc file được download từ Email bằng Objective C???
- Mfc c++
- Thắc mắc cách tạo project Java đơn giản bằng Xcode
- [Thắc mắc] Cách sử dụng thư viện dựng sẵn igraph.h dành cho C++ trên VS 2013
- các bạn giải giúp mình bài mảng này với mình mới học lập trình c về mảng 1 chiều, cảm ơn trước ạ :)
- Làm thế nào để tạo một thư viện (.dylib) dùng cho iOS dựa trên code c/c++ từ các thư viện open-source, môi trường Xcode 5.x
-
30-08-2013, 02:29 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi Noob_
-
30-08-2013, 03:53 PM #3Banned
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Hi bạn,
Nếu format trả về không phải json thì bạn có thể dùng RequestOperation bình thường [IMG]images/smilies/smile.png[/IMG]
Mã://Tạo request với url là link tới forum NSURLRequest *afRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://kites.vn/51-1/tv-series.html"]]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Response:%@", operation.responseString); //Bạn parse HTML (operation.responseString) ra là lấy được thông tin. //Lib để parser html thì nhiều: mình google ra cái này, bạn xem thử nhé //https://github.com/zootreeves/Objective-C-HMTL-Parser }failure:^(AFHTTPRequestOperation *operation, NSError *error) { // xử lý khi request không thành công }]; [operation start];
Chúc bạn thành công.[IMG]images/smilies/2.gif[/IMG]
-
31-08-2013, 10:31 AM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Ồ... trường hợp này bạn phải add một cái gọi là accept type cho request header từ AFNetworking nhé
!
-
05-09-2013, 08:18 AM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi mrqgenius
-
05-09-2013, 02:52 PM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Nếu không ngại vấn đề hiệu suất bạn thử làm một cái proxy trên host của bạn để ép nó về dữ liệu json rồi truy xuất qua host của bạn xem sao.
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...