JSON解析网络数据

类似如此
1.设置info允许网络请求
2.找到接口文件运行到鬼脸
3.Appdelegate指定默认根视图,并且建立MVC管理模式,建立model类,以及自定义cellXIB类,model中图示:这里写图片描述
这里写图片描述
这里主要是要在鬼脸接口文件中找到对应的对象名并且定义.
4.在自定义cell中设置xib的位置界面设置,并且通过拖拽完成在.h中定义属性
并且在.h声明方法- (void)setValueForCellWithBook:(Book *)book;
在.m中赋值,给出值,实现声明的方法


#import "BookCell.h"

@implementation BookCell

-(void)setValueForCellWithBook:(Book *)book{
    if (book) {
        self.imgV.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:book.iconUrl]]];
        self.label1.text = book.name;
        self.label2.text = book.expireDatetime;
        self.label3.text = [NSString stringWithFormat:@"分享:%@次",book.shares];
        self.label4.text = [NSString stringWithFormat:@"收藏:%@次",book.favorites];
        self.label5.text = [NSString stringWithFormat:@"下载:%@次",book.downloads];
        self.label6.text = book.categoryName;
        self.label7.text = book.lastPrice;
    }
}
@end

5.完成viewcontroller中的界面搭建并且请求解析数据如下

//
//  ViewController.m
//  练习JSON解析
#import "ViewController.h"
#import "Book.h"
#import "BookCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic , strong)UITableView *ojtable;
@property(nonatomic , strong)NSMutableArray *arr;

@end

@implementation ViewController
- (UITableView *)ojtable{
    if (!_ojtable) {
        _ojtable = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
        _ojtable.delegate = self;
        _ojtable.dataSource =self;
        
    }
    return _ojtable;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title= @"降价";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"设置" style:UIBarButtonItemStyleDone target:self action:nil];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"分类" style:UIBarButtonItemStyleDone target:self
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值