Skip to content
/ YIModel Public

A simple way to mapping JSON to NSObject(s). Like JTObjectMapping, RestKit.

License

Notifications You must be signed in to change notification settings

zvving/YIModel

Repository files navigation

The project was Deprecated!
Please use the better project that is JsonModel.

YIModel

A simple way to mapping JSON to NSObject(s).

YIModel

Feature

  • Transform JSON to Model Instance in 1 line code;
  • Property compatible with BOOL, int, float;
  • Serializable, implemented NSCoding;
  • Can clone, like [oneObject copy], implemented NSCopy;

Demo

JSON

{						// one User
	name: xiaoming,
	age: 26,
	best_friend: {		// other User
		name: xiaohong,
		age: 27,
	},
	books:[				// two Books
		{
			book_name: The Little Prince,
			price: 10
		},
		{
			book_name: Jobs,
			price: 50.5
		}	
	],
}

Subclass

@interface User : YIModel			// Subclass from YIModel

@property (nonatomic, copy)     NSString *          name;
@property (nonatomic, assign)   int                 ageI;
@property (nonatomic, strong)   User *              bestFriend;
@property (nonatomic, strong)   NSArray *           booksArr;

@end

@implementation User

+ (NSDictionary *)parseFormat		// implemente it.
{
    return @{
             @"name"            : @"name",
             @"ageI"            : @"age",
             @"bestFriend"      : @[ @"best_friend", User.class ],
             @"booksArr"        : @[ @"books", @[ Book.class ] ],
             };
}

@end

Just Use It.

User *user = [User modelFromDictionary:jsonUser];	// transform in 1 line.
// user.name 				=> @"xiaoming"
// user.bestFriend.name 	=> @"xiaohong"

Book *b0 = user.booksArr.firstObject;
// b0.name 					=> @"The Little Prince"

One More Thing

Implemented NSCoding&NSCopy yet

NSData *serializedUser [NSKeyedArchiver archivedDataWithRootObject:user];
// ok!

User *cloneUser = [user copy];
// ok!

Others

About

A simple way to mapping JSON to NSObject(s). Like JTObjectMapping, RestKit.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published