ios - Serialize a custom object with JSONModel -
i try create json file out of custom object jsonmodel framework ios. error:
-[jsonmodel.m:1077] exception: invalid type in json write (registerbuyerdataoption) -[jsonmodel.m:1077] exception: invalid type in json write (registerbuyerdataoption) -[jsonmodel.m:1077] exception: invalid type in json write (registerbuyerdata)
registerbuyerdata.h
@interface registerbuyerdata : jsonmodel @property (nonatomic, strong) nsstring *buyerdataid; @property (nonatomic ) registerbuyerdatatype type; @property (nonatomic, strong) nsstring<optional> *title; @property (nonatomic ) bool required; @property (nonatomic, strong) nsstring *value; @property (nonatomic) nsnumber<optional> *price; @property (nonatomic) nsnumber<optional> *availability; @property (nonatomic, strong) nsarray<registerbuyerdata*> *fields; //array of more registerbuyerdata @property (nonatomic, strong) nsarray<registerbuyerdataoption*> *options; //key,value array dropdown @property (nonatomic, strong) nsarray *parentvalue; @property (nonatomic, strong) nsarray<registerbuyerdata*> *children; //array of more registerbuyerdata special selected value of options field - (bool) isavailableforuser; @end
registerbuyerdata.m
@implementation registerbuyerdata - (bool) isavailableforuser{ return (!_availability || [_availability integervalue] > 0 ); } +(jsonkeymapper*)keymapper { return [[jsonkeymapper alloc] initwithdictionary:@{@"id": @"buyerdataid",@"value": @"value"}]; } @end
registerbuyerdataoption.h
@interface registerbuyerdataoption : jsonmodel @property (nonatomic, strong) nsstring *key; @property (nonatomic, strong) nsstring *value; @property (nonatomic, strong) nsnumber *price; @property (nonatomic, strong) nsnumber *availability; - (bool) isavailableforuser; @end
is not possible create json string recursively? when call tojsonstring method these errors.
@property (nonatomic, strong) nsarray<registerbuyerdata*> *fields;
should be
@property (nonatomic, strong) nsarray<registerbuyerdata> *fields;
so rid of *
, try again.
edit:
oh, see. seems haven't declared types want cascade protocols. following
registerbuyerdataoption.h
@protocol registerbuyerdataoption @end; @interface registerbuyerdataoption : jsonmodel @property (nonatomic, strong) nsstring *key; @property (nonatomic, strong) nsstring *value; @property (nonatomic, strong) nsnumber *price; @property (nonatomic, strong) nsnumber *availability; - (bool) isavailableforuser; @end
registerbuyerdata.h
@protocol registerbuyerdata @end; @interface registerbuyerdata : jsonmodel @property (nonatomic, strong) nsstring *buyerdataid; @property (nonatomic ) registerbuyerdatatype type; @property (nonatomic, strong) nsstring<optional> *title; @property (nonatomic ) bool required; @property (nonatomic, strong) nsstring *value; @property (nonatomic) nsnumber<optional> *price; @property (nonatomic) nsnumber<optional> *availability; @property (nonatomic, strong) nsarray<registerbuyerdata*> *fields; //array of more registerbuyerdata @property (nonatomic, strong) nsarray<registerbuyerdataoption*> *options; //key,value array dropdown @property (nonatomic, strong) nsarray *parentvalue; @property (nonatomic, strong) nsarray<registerbuyerdata*> *children; //array of more registerbuyerdata special selected value of options field - (bool) isavailableforuser; @end
Comments
Post a Comment