【发布时间】:2013-03-20 14:06:08
【问题描述】:
有没有办法在请求中创建字符串数组? 我确实找到了一些响应解决方案,但其中大多数是 restkit 0.10.x 或者我不理解它们。 (例如Mapping relationships in RestKit through an array of IDs doesn't work)
这是我的设置: 我将 iOS 6 与核心数据和托管对象一起使用。我的要求应该是这样的
{
"attribute":["some text", "some more text", "and one more text"],
"relationship":[some object data],
"string":"some text"
}
该实体称为“doRequest”。 “关系”是与其他托管对象的关系,“字符串”是一个属性。我想将“属性”作为属性,但无法将“属性”设置为字符串数组。所以“属性”是与具有“文本”属性的实体“子属性”的一对多关系。
我的休息套件映射: RKObjectMapping *subAttributeMapping = [RKObjectMapping requestMapping]; [subAttributeMapping addAttributeMappingsFromArray:@[@"text"]];
RKObjectMapping *doRequestMapping = [RKObjectMapping requestMapping];
[doRequestMapping addAttributeMappingsFromDictionary:@{
@"string": @"string"}];
[doRequestMapping addRelationshipMappingWithSourceKeyPath:@"attribute" mapping:subAttributeMapping];
[doRequestMapping addRelationshipMappingWithSourceKeyPath:@"relationship" mapping:relationshipMapping];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:doRequestMapping objectClass:[DoRequest class] rootKeyPath:nil];
[objectManager addRequestDescriptor:requestDescriptor];
Restkit 映射如下:
{
"attribute":[{"text":"some text"}, {"text":"some more text"}, {"text":"and one more text"}],
"relationship":[some object data],
"string":"some text"
}
但这不是我需要的。 你能帮帮我吗?
【问题讨论】:
-
您要发送的请求不是有效的 JSON 格式(请参阅jsonlint.com)。也许在发送对象之前尝试配置
attribute的内容有效? -
JSON 只是展示我想做的一个例子。所以我知道,“一些对象数据”不是一个有效的表达方式。 ;-) 但感谢您的回答。就像你说的那样,我在发送之前配置我的内容。