我是新来的kit2.0。对一对多关系有一些问题。 下面是我的模型,restkit实现& json回应。
@interface **DocumentCategory** : NSManagedObject
@property (nonatomic, retain) NSNumber * categoryDeleted;
@property (nonatomic, retain) NSString * categoryDeviceIconUrl;
@property (nonatomic, retain) NSNumber * categoryId;
@property (nonatomic, retain) NSString * categoryName;
@property (nonatomic, retain) NSString * categoryServerIconUrl;
@property (nonatomic, retain) NSOrderedSet *documentObjects;
@end
@interface **AppDocument** : NSManagedObject
@property (nonatomic, retain) NSNumber * documentDeleted;
@property (nonatomic, retain) NSString * documentDesc;
@property (nonatomic, retain) NSString * documentIconDeviceUrl;
@property (nonatomic, retain) NSString * documentIconServerUrl;
@property (nonatomic, retain) NSNumber * documentId;
@property (nonatomic, retain) NSString * documentName;
@property (nonatomic, retain) NSString * documentPdfDeviceUrl;
@property (nonatomic, retain) NSString * documentPdfServerUrl;
@property (nonatomic, retain) NSString * documentVideoDeviceUrl;
@property (nonatomic, retain) NSString * documentVideoServerUrl;
@property (nonatomic, retain) DocumentCategory *categoryObject;
@end
这是我的休息套件实施
RKEntityMapping *documentCategoryMapping = [RKEntityMapping mappingForEntityForName:@"DocumentCategory" inManagedObjectStore:objectManager.managedObjectStore];
[documentCategoryMapping addAttributeMappingsFromDictionary:@{
@"Id":@"categoryId",
@"CategoryDeleted":@"categoryDeleted",
@"CaegoryName":@"categoryName",
@"CategoryServerIconUrl":@"categoryServerIconUrl"
}];
RKEntityMapping *appDocumentMapping = [RKEntityMapping mappingForEntityForName:@"AppDocument" inManagedObjectStore:objectManager.managedObjectStore];
[appDocumentMapping addAttributeMappingsFromDictionary:@{
@"Id": @"documentId",
@"AppDescription": @"documentDesc",
@"documentDeleted": @"documentDeleted",
@"AppIcon": @"documentIconServerUrl",
@"Title": @"documentName",
@"AppPDFurl": @"documentPdfServerUrl",
@"AppVideourl": @"documentVideoServerUrl"
}];
[appDocumentMapping setIdentificationAttributes:[NSArray arrayWithObjects:@"documentId", nil]];
[appDocumentMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"AppCategoryIDId" toKeyPath:@"categoryObject" withMapping:documentCategoryMapping]];
RKResponseDescriptor *documentDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:appDocumentMapping method:RKRequestMethodAny pathPattern:@"AppHelp/AppDetails" keyPath:@"d.results" statusCodes:statusCodes];
//[objectManager addResponseDescriptorsFromArray:[NSArray arrayWithObjects:categoryDescriptor,documentDescriptor,appDetailsDescriptor,appDetailsForVersionDescriptor,errorDescriptor, nil]];
[objectManager addResponseDescriptorsFromArray:[NSArray arrayWithObjects:categoryDescriptor,documentDescriptor,errorDescriptor, nil]];
[[RKObjectManager sharedManager] getObjectsAtPath:@"AppHelp/AppCategory" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
// NSLog(@"Loading mapping result: %@", mappingResult);
//[self hideProgressHUD];
[[RKObjectManager sharedManager] getObjectsAtPath:@"AppHelp/AppDetails" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
// NSLog(@"Loading mapping result: %@", mappingResult);
[self hideProgressHUD];
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
//NSLog(@"error %@",[error description]);
[self hideProgressHUD];
}];
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
//NSLog(@"error %@",[error description]);
[self hideProgressHUD];
}];
通过以上实现,我收到以下错误消息。
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFNumber 0xbd5bad0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key CategoryServerIconUrl.'
感谢您宝贵的时间,我们将非常感谢您提供解决方案/帮助/建议。
以下是json的回复。
对于第一个请求,我得到低于响应。
{
"d": {
"results": [
{
"__metadata": {
"uri": "/listdata.svc/AppCategory(1)",
"etag": "W/\"3\"",
"type": "Microsoft.SharePoint.DataService.AppCategoryItem"
},
"ContentTypeID": "0x01006A3A58069D41EF409018396EB125A5E9",
"CaegoryName": "Productivity",
"CategoryServerIconUrl": "http://www.google.com, http://www.google.com",
"CategoryDeleted": false,
"Id": 1,
"ContentType": "Item",
"Modified": "\/Date(1404806841000)\/",
"Created": "\/Date(1403657024000)\/",
"CreatedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(1)/CreatedBy"
}
},
"CreatedById": 60,
"ModifiedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(1)/ModifiedBy"
}
},
"ModifiedById": 26215,
"Owshiddenversion": 3,
"Version": "1.0",
"Attachments": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(1)/Attachments"
}
},
"Path": "/sites/gis/Mobile Apps/Lists/AppCategory"
},
{
"__metadata": {
"uri": "/listdata.svc/AppCategory(2)",
"etag": "W/\"3\"",
"type": "Microsoft.SharePoint.DataService.AppCategoryItem"
},
"ContentTypeID": "0x01006A3A58069D41EF409018396EB125A5E9",
"CaegoryName": "Business",
"CategoryServerIconUrl": "http://www.google.com, http://www.google.com",
"CategoryDeleted": false,
"Id": 2,
"ContentType": "Item",
"Modified": "\/Date(1404806874000)\/",
"Created": "\/Date(1403657032000)\/",
"CreatedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(2)/CreatedBy"
}
},
"CreatedById": 60,
"ModifiedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(2)/ModifiedBy"
}
},
"ModifiedById": 26215,
"Owshiddenversion": 3,
"Version": "1.0",
"Attachments": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(2)/Attachments"
}
},
"Path": "/sites/gis/Mobile Apps/Lists/AppCategory"
},
{
"__metadata": {
"uri": "/listdata.svc/AppCategory(3)",
"etag": "W/\"3\"",
"type": "Microsoft.SharePoint.DataService.AppCategoryItem"
},
"ContentTypeID": "0x01006A3A58069D41EF409018396EB125A5E9",
"CaegoryName": "Connectivity",
"CategoryServerIconUrl": "http://www.google.com, http://www.google.com",
"CategoryDeleted": false,
"Id": 3,
"ContentType": "Item",
"Modified": "\/Date(1404806911000)\/",
"Created": "\/Date(1403657047000)\/",
"CreatedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(3)/CreatedBy"
}
},
"CreatedById": 60,
"ModifiedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(3)/ModifiedBy"
}
},
"ModifiedById": 26215,
"Owshiddenversion": 3,
"Version": "1.0",
"Attachments": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(3)/Attachments"
}
},
"Path": "/sites/gis/Mobile Apps/Lists/AppCategory"
},
{
"__metadata": {
"uri": "/listdata.svc/AppCategory(4)",
"etag": "W/\"3\"",
"type": "Microsoft.SharePoint.DataService.AppCategoryItem"
},
"ContentTypeID": "0x01006A3A58069D41EF409018396EB125A5E9",
"CaegoryName": "General",
"CategoryServerIconUrl": "http://www.google.com, http://www.google.com",
"CategoryDeleted": false,
"Id": 4,
"ContentType": "Item",
"Modified": "\/Date(1404806934000)\/",
"Created": "\/Date(1403823724000)\/",
"CreatedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(4)/CreatedBy"
}
},
"CreatedById": 23323,
"ModifiedBy": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(4)/ModifiedBy"
}
},
"ModifiedById": 26215,
"Owshiddenversion": 3,
"Version": "1.0",
"Attachments": {
"__deferred": {
"uri": "/listdata.svc/AppCategory(4)/Attachments"
}
},
"Path": "/sites/gis/Mobile Apps/Lists/AppCategory"
}
]
}
}
收到回复后,点击另一个请求以获取文件json。
{
"d": {
"results": [
{
"__metadata": {
"uri": ")",
"etag": "W/\"1\"",
"type": ""
},
"ContentTypeID": "0x010050E1B3AE1BFD2846A6ED8237F2BDDB29",
"Title": "SkyMobile SRM",
"AppCategoryID": {
"__deferred": {
"uri": ")/AppCategoryID"
}
},
"AppCategoryIDId": 2,
"AppDescription": "",
"AppIcon": " ",
"AppPDFurl": "",
"AppVideourl": null,
"Id": 1,
"ContentType": "Item",
"Modified": "\/Date(1403657407000)\/",
"Created": "\/Date(1403657407000)\/",
"CreatedBy": {
"__deferred": {
"uri": ")/CreatedBy"
}
},
"CreatedById": 60,
"ModifiedBy": {
"__deferred": {
"uri": ")/ModifiedBy"
}
},
"ModifiedById": 60,
"Owshiddenversion": 1,
"Version": "1.0",
"Attachments": {
"__deferred": {
"uri": ")/Attachments"
}
},
"Path": "/ils"
}
]
}
}
注意:我有两个单独的URL用于分类,另一个用于文档。 文档josn响应包含 AppCategoryIDId ,它是类别主键。