Reputation: 996
How to serialize a custom object with JSONModel ?
@property(nonatomic,strong) NSString<Optional> * tag_post_type;
@property(nonatomic,strong) NSString<Optional> * tag_users_type;
@property(nonatomic,strong) NSArray<Optional> * tags;
@property(nonatomic,strong) NSMutableArray<TagMediaModel*>* tag_posts;
@property(nonatomic,strong) NSMutableArray<TagLocationModel*>* locations;
I try to create a JSON file out of my custom Object with the JSONModel framework for iOS. I get the Error:
EXCEPTION: Invalid type in JSON write (TagMediaModel)
When I call toJSONString Method, I got this issue.
[tagAutomaticModel toJSONString];
This is the model data:
locations = (
"<TagLocationModel> \n [id]: 780307344\n [name]: Hotel Central Park, india\n</TagLocationModel>",
"<TagLocationModel> \n [id]: 463004401\n [name]: Miraj Cinema new year\n</TagLocationModel>",
"<TagLocationModel> \n [id]: 246187965\n [name]: Surya Treasure Island asia\n</TagLocationModel>",
);
"tag_posts" = (
"<TagMediaModel> \n [media_code]: BS0tQeFhU_Z\n [media_id]: 1492016420475981785\n [media_url]: https://scontent.cdninstagram.com/t51.2885-15/e15/17881459_...\n [media_type]: I\n</TagMediaModel>"
);
Upvotes: 0
Views: 334
Reputation: 5510
The angle brackets after NSMutableArray contain a protocol. As @R.Mohan said, you need to remove
* pointer
and use without pointer
.
@protocol tag_posts
and @protocol locations
at top in respective class.EXCEPTION: Invalid type in JSON write (TagMediaModel)
I guess you are converting json to your custom class one or more times. Do it only once. It will resolve your problem.Upvotes: 0
Reputation: 2209
@property(nonatomic,strong) NSMutableArray<TagMediaModel>* tag_posts;
made few change as above, just removed the star in TagMediaModel.
Upvotes: 1