微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Motis JSON 到 NSObject 的映射库

程序名称:Motis

授权协议: Apache

操作系统: iOS

开发语言: Objective-C

Motis 介绍

Motis 使用 Cocoa 的 KVC 实现了智能的 JSON 到 NSObject 对象的映射。

示例代码

// --- User.h --- //

@interface User : NSObject

@property (nonatomic, strong) Nsstring *name;
@property (nonatomic, assign) NSIntger userId;
@property (nonatomic, strong) NSDate *creationDate;
@property (nonatomic, strong) NSURL *website;
@property (nonatomic, assing) NSInteger views;
@property (nonatomic, assing) NSInteger ranking;

@end

// --- User.m --- //

@implementation User

+ (NSDictionary*)mts_mapping
{
    return @{@"user_name": mts_key(name),
             @"user_id": mts_key(userId),
             @"creation_date": mts_key(creationDate),
             @"website": mts_key(website),
             @"user_stats.views": mts_key(views),  // <-- KeyPath access
             @"user_stats.ranking": mts_key(ranking), // <-- KeyPath access
            };
}

@end

Motis 官网

https://github.com/mobilejazz/Motis

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐