Ios RestKit 0.20.0 rc1-使用字符串数组创建请求发布
有没有办法在请求中创建字符串数组? 我确实找到了一些响应解决方案,但大多数都是restkit0.10.x,或者我不理解它们。(例如) 这是我的设置: 我将iOS 6用于核心数据和托管对象。我的要求应该是Ios RestKit 0.20.0 rc1-使用字符串数组创建请求发布,ios,ios6,request,restkit,Ios,Ios6,Request,Restkit,有没有办法在请求中创建字符串数组? 我确实找到了一些响应解决方案,但大多数都是restkit0.10.x,或者我不理解它们。(例如) 这是我的设置: 我将iOS 6用于核心数据和托管对象。我的要求应该是 { "attribute":["some text", "some more text", "and one more text"], "relationship":[some object data], "string":"some text" } 该实体称为“doRequest”。“
{
"attribute":["some text", "some more text", "and one more text"],
"relationship":[some object data],
"string":"some text"
}
该实体称为“doRequest”。“关系”是与其他托管对象的关系,“字符串”是属性。我希望将“attribute”作为属性,但无法将“attribute”设置为字符串数组。因此,“属性”是与属性为“文本”的实体“子属性”的一对多关系
我的rest工具包映射:
RKObjectMapping*子属性映射=[RKObjectMapping requestMapping];
[子属性映射addAttributeMappingsFromArray:@[@“text”]
Restkit映射如下:
{
"attribute":[{"text":"some text"}, {"text":"some more text"}, {"text":"and one more text"}],
"relationship":[some object data],
"string":"some text"
}
但那不是我需要的。
你能帮帮我吗?所以,我只使用对象而不使用核心数据来修复它。 我的对象现在有一个新属性
NSArray*attributeArray
来创建一个字符串数组
我的梦想。h:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface DoRequest : NSManagedObject
@property (nonatomic, retain) NSString * string;
@property (nonatomic, retain) NSSet * relationship;
@property (nonatomic, retain) NSSet *attribute;
@property (nonatomic, retain) NSArray *attributeArray;
@end
@interface DoRequest (CoreDataGeneratedAccessors)
- (void)addRelationshipObject:(RelationshipReference *)value;
- (void)removeRelationshipObject:(RelationshipReference *)value;
- (void)addRelationship:(NSSet *)values;
- (void)removeRelationship:(NSSet *)values;
- (void)addAttributeObject:(NSManagedObject *)value;
- (void)removeAttributeObject:(NSManagedObject *)value;
- (void)addAttribute:(NSSet *)values;
- (void)removeAttribute:(NSSet *)values;
@end
我的对象映射器看起来像:
RKObjectMapping *doRequestMapping = [RKObjectMapping requestMapping];
[doRequestMapping addAttributeMappingsFromDictionary:@{
@"string": @"string",
@"attributeArray": @"attribute"}];
[doRequestMapping addRelationshipMappingWithSourceKeyPath:@"relationship" mapping:[self relationshipReferenceObjectMapping]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:doRequestMapping objectClass:[DoQueryRequest class] rootKeyPath:nil];
[objectManager addRequestDescriptor:requestDescriptor];
您要发送的请求不是有效的JSON格式(请参阅)。可能是在发送对象之前尝试配置
属性的内容
?JSON只是一个示例,展示了我想要做的事情。所以我知道,“某些对象数据”不是有效的表达式。;-)但是谢谢你的回答。我正在配置我的内容,然后再发送它,就像你说的那样。
#import "DoRequest.h"
#import "RelationshipReference.h"
#import "Attribute.h"
@implementation DoRequest
@dynamic string;
@dynamic relationship;
@dynamic attribute;
@dynamic attributeArray;
- (NSArray *)attributeArray
{
NSMutableArray *array = [[NSMutableArray alloc] init];
for (Attribute.h *object in self.attribute) {
[array addObject:object.attributeName];
}
return [array copy];
}
@end
RKObjectMapping *doRequestMapping = [RKObjectMapping requestMapping];
[doRequestMapping addAttributeMappingsFromDictionary:@{
@"string": @"string",
@"attributeArray": @"attribute"}];
[doRequestMapping addRelationshipMappingWithSourceKeyPath:@"relationship" mapping:[self relationshipReferenceObjectMapping]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:doRequestMapping objectClass:[DoQueryRequest class] rootKeyPath:nil];
[objectManager addRequestDescriptor:requestDescriptor];