码迷,mamicode.com
首页 > Web开发 > 详细

AFNetworking网上加载数据及JSON解析

时间:2015-08-27 22:49:41      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

 

引用第三方库AFNetworking

#import "AFNetworking.h"

#import "UIKit+AFNetworking.h"

- (void)downloadData
{
    NSString *urlString = [NSString stringWithFormat:LIMIT_URL,_page,_categoryId];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //JSON解析数据
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSArray *apps = dict[@"applications"];
        for (NSDictionary *appDict in apps) {
            AppModel *model = [[AppModel alloc] init];
            [model setValuesForKeysWithDictionary:appDict];
            model.desc = appDict[@"description"];
            [_dataArray addObject:model];

            [self.tableView reloadData];//若刷新表格需在block块内
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

通过AFNetworking,使用url从网上加载图片(#import "UIKit+AFNetworking.h")

 [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.iconUrl]]; 

 

AFNetworking网上加载数据及JSON解析

标签:

原文地址:http://www.cnblogs.com/caolongs/p/4764740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!