ios - How to use 'Mantle' -


this model :

@interface zpcouncilvclrapplistmodel : mtlmodel <mtljsonserializing> @property (nonatomic , assign) long long theid ; // 应用编号 @property (nonatomic , assign) nsuinteger index ; // 应用名称 @property (nonatomic , strong) nsstring *name ; // 顺序号 @property (nonatomic , assign) nsinteger version ; // 最新版本号 @end  @interface zpcouncilvclrcenteradvmodel : mtlmodel <mtljsonserializing> @property (nonatomic , strong) nsstring *title ; // 标题 @property (nonatomic , strong) nsstring *imageurl ; // 图片url @property (nonatomic , strong) nsstring *tourl ; // 链接地址url @end  @interface zpcouncilvclrnewslistmodel : mtlmodel <mtljsonserializing> @property (nonatomic , strong) nsstring *title ; // 标题 @property (nonatomic , strong) nsstring *imageurl ; // 图片 @property (nonatomic , assign) nstimeinterval createdate ; // 时间 @end  @interface zpcouncilvclrtopadvmodel : mtlmodel <mtljsonserializing> @property (nonatomic , strong) nsstring *title ; // 标题 @property (nonatomic , strong) nsstring *imageurl ; // 图片url @property (nonatomic , strong) nsstring *tourl ; // 链接地址url @end  @interface zpcouncilvclrmodel : mtlmodel <mtljsonserializing> @property (nonatomic , strong) nsarray<zpcouncilvclrapplistmodel *>* applist ; @property (nonatomic , strong) nsarray<zpcouncilvclrcenteradvmodel *>* centeradv ; @property (nonatomic , strong) nsarray<zpcouncilvclrnewslistmodel *>* newslist ; @property (nonatomic , strong) nsarray<zpcouncilvclrtopadvmodel *>* topadv ; + (zpcouncilvclrmodel *)createmodelwith:(nsdictionary *)jsonparams ; @end 

this implement :

@implementation zpcouncilvclrapplistmodel +(nsdictionary *)jsonkeypathsbypropertykey {     return @{@"theid":@"id"} ; } @end @implementation zpcouncilvclrcenteradvmodel +(nsdictionary *)jsonkeypathsbypropertykey {     return @{} ; } @end @implementation zpcouncilvclrnewslistmodel +(nsdictionary *)jsonkeypathsbypropertykey {     return @{} ; } @end @implementation zpcouncilvclrtopadvmodel +(nsdictionary *)jsonkeypathsbypropertykey {     return @{} ; } @end @implementation zpcouncilvclrmodel +(nsdictionary *)jsonkeypathsbypropertykey {     return @{} ; } + (zpcouncilvclrmodel *)createmodelwith:(nsdictionary *)jsonparams {     nserror *error ;     zpcouncilvclrmodel *jsonmodel = [mtljsonadapter modelofclass:[self class] fromjsondictionary:jsonparams error:&error];     if( error ){         return nil ;     }     return jsonmodel ; }  @end 

you can see method :

[ + (zpcouncilvclrmodel *)createmodelwith:(nsdictionary *)jsonparams ] 

in method , use mtljsonadapter class convert json dictionary zpcouncilvclrmodel* object .
can see code

zpcouncilvclrmodel *jsonmodel = [mtljsonadapter modelofclass:[self class] fromjsondictionary:jsonparams error:&error]; 

but !

i check result , found object(the name jsonmodel) exist , jsonmodel's property nil !

can me , why jsonmodel's property nil ? in advance.


Comments