Storing the requested data (array and single data) in the model

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.