如何使用 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;
视图控制器
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