如何映射下面的嵌套json與RestKit RKObjectMapping?我只需要映射「數據」。我目前的代碼返回(空) - 謝謝!RestKit RKObjectMapping嵌套json
{
"sucess": true,
"error": {
"code": "",
"message": ""
},
"data": [
{
"id": 1,
"name": "Salad",
"description": "Salad Desc",
"category_id": 1
},
{
"id": 2,
"name": "Soup",
"description": "Soup Desc",
"category_id": 1
},
{
"id": 3,
"name": "Wrap",
"description": "Wrap Desc",
"category_id": 1
},
{
"id": 4,
"name": "Appetizers",
"description": "Appetizers Desc",
"category_id": 1
}
]
}
類
@interface Subcategory : NSObject
@property (nonatomic, retain) NSNumber *subcategoryID;
@property (nonatomic, retain) NSNumber *categoryID;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *thumbnail;
@property (nonatomic, retain) NSArray *data;
的ViewController
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[Subcategory class]];
RKObjectMapping* dataMapping = [RKObjectMapping mappingForClass:[Subcategory class]];
[dataMapping mapKeyPath:@"id" toAttribute:@"subcategoryID"];
[dataMapping mapKeyPath:@"category_id" toAttribute:@"categoryID"];
[dataMapping mapAttributes:@"name", @"description", nil];
[mapping mapKeyPath:@"data" toRelationship:@"data" withMapping:dataMapping];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[NSString stringWith
爲了他人的利益,https://github.com/RestKit/RestKit/wiki/Object-mapping是開始時的重要資源來RK對象映射。 – 2012-07-19 22:44:57
快速的問題,我不是一個ObjC大師,但我被告知NSString屬性應該是'複製'而不是'保留',但我看到NSString屬性保留在相當多的開源項目和帖子在這裏 - 是在這種情況下使用'保留'的理由@steamboy? – powerj1984 2012-12-10 03:05:59