我有一个关于映射嵌套数组的问题。在https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md上有一个用于映射嵌套对象的示例。
但是,如果嵌套对象是对象数组,我该怎么办,例如 JSON 看起来像:
{ "articles": [
{ "title": "RestKit Object Mapping Intro",
"body": "This article details how to use RestKit object mapping...",
"author": [{
"name": "Blake Watters",
"email": "blake@restkit.org"
},
{
"name": "abc",
"email": "emailaddress"
}]
"publication_date": "7/4/2011"
}]
}
为了获得一组作者,我的课程应该是什么样子?这就是示例中的代码:
@interface Author : NSObject
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* email;
@end
@interface Article : NSObject
@property (nonatomic, retain) NSString* title;
@property (nonatomic, retain) NSString* body;
@property (nonatomic, retain) Author* author; // should be an array of Author-Objects
@property (nonatomic, retain) NSDate* publicationDate;
@end
我如何告诉 Restkit,有一个作者数组,如果我将文章中的作者属性的类更改为 NSArray,Restkit 怎么知道,在这个 NSArray 中应该是 Author-Objects ......?
我正在使用 RKObjectMapping 将对象从 JSON 映射到 Objective-c,反之亦然。