#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;
}
method of Use;
Isolate the required data from the parsed array and store it in the dictionary of the Class
Nsmutabledictionary *dic = [responseobject objectforkey:@ "Data"];
Playingmodel *model = [[Playingmodel alloc] initwithdictionary:dic];
2. Model is stored in the dictionary (data stored in model)
#import <Foundation/Foundation.h>
@interface Playingmodel:nsobject
@property (nonatomic, copy) NSString *t; Title bar ...
@property (nonatomic, copy) NSString *tag;
@property (nonatomic, copy) NSString *desc;
@property (nonatomic, copy) NSString *picpath; Image Address
@property (nonatomic, copy) NSString *bigpicpath;
@property (nonatomic, assign) Nsinteger vtime;
@property (nonatomic, copy) NSString *f; Video playback Address
-(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
/***************
Remember, * * * *
**************/
When the object is not empty, it is not empty.
if (![ [[Responseobject objectforkey:@ "Data"] objectforkey:@ "List"] Iskindofclass:[nsnull class]) {
Nsmutablearray *arr = [[Responseobject objectforkey:@ "Data"] objectforkey:@ "list"];
Self.arraycomment = [Videopinglunmodel Modelsformdics:arr];
}
Dictionary editing
+ (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 (@ "field value ID read exception (field does not exist or value is empty)");
}
}
Storing the requested data (array and single data) in the model