您好,登录后才能下订单哦!
1、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读取异常(字段不存在或者值为空)");
    }
}免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。