你試過地幔(https://github.com/Mantle/Mantle)? 您可以定義屬性的類型的值你所期望:
@property (nonatomic, copy, readonly) NSURL *URL;
@property (nonatomic, copy, readonly) NSURL *HTMLURL;
@property (nonatomic, copy, readonly) NSNumber *number;
@property (nonatomic, assign, readonly) GHIssueState state;
@property (nonatomic, copy, readonly) NSString *reporterLogin;
@property (nonatomic, strong, readonly) GHUser *assignee;
@property (nonatomic, copy, readonly) NSDate *updatedAt;
然後你就可以知道哪個屬性在此方法中JSONKeyPathsByPropertyKey匹配,如:
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"URL": @"url",
@"HTMLURL": @"html_url",
@"number": @"number",
@"state": @"state",
@"reporterLogin": @"user.login",
@"assignee": @"assignee",
@"updatedAt": @"updated_at"
};
確保您的目標是一個MTLModel的子類,並符合MTLJSONSerializing協議,如下所示:
@interface GHIssue : MTLModel <MTLJSONSerializing>
我還沒試過。但是從掃描Github頁面,我可以看到Mantle是如何比JSONModel更好的映射器。事情是,它仍然基本上只是一個映射器。我肯定會去看看,謝謝! – keyboardsamurai