-
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:
- Có mấy cách import Framework khi làm việc với Xcode?
- Cách lấy danh sách các app đang ở trên Desktop
- V/v Pin point google map
- Hiển thị ảnh lên UIScrollview lỗi: Terminating app due to uncaught exception ... was mutated while being enumerated?
- Làm thế nào để bắt sự kiện hiển thị thay đổi trong app iOS?
- Cách đọc file được download từ Email bằng Objective C???
- Cách dùng TableView trong iOS như thế nào?
- các pro chỉ em cách chèn file flash đuôi .swf và xcode với!
- Từ Navigationbar ra được nhiều cửa sổ view
- Objective-c vs Java đối với cross platform mobile application.
-
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.
Pallet nhựa Lâm Đồng giải pháp hoàn hảo cho nhà kho Pallet nhựa Lâm Đồng là một giải pháp đa năng và hiệu quả trong việc vận chuyển và lưu trữ hàng hóa. Trong đó, pallet nhựa Lâm Đồng không chỉ đáp...
Pallet nhựa Lâm Đồng giải pháp...