把请求的数据(数组和和单条数据)存放到Model中

#import <Foundation/Foundation.h>

@interface VideoPinglunModel : NSObject

@property (nonatomic , assign)NSInteger commentUserid;

@property (nonatomic , assign)NSInteger commentCtime;

@property (nonatomic , copy)NSString *commentContent;

@property (nonatomic , copy)NSString *commentAuthor;

- (instancetype)initWithDictionary:(NSDictionary *)dic;

+ (NSMutableArray *)modelSformDics:(NSArray *)arr;

@end

- (void)setValue:(id)value forUndefinedKey:(NSString *)key

{

//    if ([key isEqualToString:@"id"]) {

//        self.idM = value;

//    }

}

- (id)valueForUndefinedKey:(NSString *)key

{

    return nil;

}

- (instancetype)initWithDictionary:(NSDictionary *)dic

{

    self = [super init];

    if (self) {

        [self setValuesForKeysWithDictionary:dic];

    }

    return self;

}

+ (NSMutableArray *)modelSformDics:(NSArray *)arr

{

    NSMutableArray *modelArr = [NSMutableArray array];

    for (NSDictionary *dic in arr) {

        VideoPinglunModel *model = [[self alloc] initWithDictionary:dic];

        [modelArr addObject:model];

    }

    return modelArr;

}

使用方法;

//从解析的数组中查出需要的数据,存放到类的字典里面

        NSMutableDictionary *dic = [responseObject objectForKey:@"data"];

        playingModel *model  = [[playingModel alloc] initWithDictionary:dic];

 

 

2、Model存放到中字典中(数据存到Model中)

 

#import <Foundation/Foundation.h>

@interface playingModel : NSObject

@property (nonatomic , copy)NSString *t;   //标题吧 。。。

@property (nonatomic , copy)NSString *tag;

@property (nonatomic , copy)NSString *desc;

@property (nonatomic , copy)NSString *picpath;   //图片地址

@property (nonatomic , copy)NSString *bigpicpath;

@property (nonatomic , assign)NSInteger vtime;

@property (nonatomic , copy)NSString *f;    //视频播放地址

- (instancetype)initWithDictionary:(NSDictionary *)dic;

+ (instancetype)modelSformDics:(NSDictionary *)dic;

@end

 

#import "playingModel.h"

@implementation playingModel

- (void)setValue:(id)value forUndefinedKey:(NSString *)key

{

   

}

- (id)valueForUndefinedKey:(NSString *)key

{

    return nil;

}

- (instancetype)initWithDictionary:(NSDictionary *)dic

{

    self = [super init];

    if (self) {

        [self setValuesForKeysWithDictionary:dic];

    }

    return self;

}

+ (instancetype)modelSformDics:(NSDictionary *)dic;

{

    playingModel *model = [[self alloc] initWithDictionary:dic];

    return model;

}

@end

 

/***************

 ****记住了*****

 **************/

            //判断这个对象不为空的时候不为空的时候

            if (![[[responseObject objectForKey:@"data"] objectForKey:@"list"] isKindOfClass:[NSNull class]]) {

                NSMutableArray *arr = [[responseObject objectForKey:@"data"] objectForKey:@"list"];

                self.arrayComment = [VideoPinglunModel modelSformDics:arr];

            }

//字典编辑

+(id)getAUsefulInstanceWith:(NSDictionary *)attributes key:(NSString *)key{

   

    if ([[attributes objectForKey:key]

         isKindOfClass:[NSNumber class]] ||

        [[attributes objectForKey:key] isKindOfClass:[NSString class]] ||

        [[attributes objectForKey:key] isKindOfClass:[NSObject class]] || ![[attributes objectForKey:key] isKindOfClass:[NSNull class]])

    {

        return [NSMutableString stringWithFormat:@"%@", [attributes objectForKey:key]];

    }

    else

    {

        return @"";

        NSLog(@"字段值Id读取异常(字段不存在或者值为空)");

    }

}

转载于:https://www.cnblogs.com/lawrence-h/p/4277930.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值