gpt4 book ai didi

ios - RestKit - 从 RKRequestDescriptor 中排除具有 nil 值的属性映射

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:22:33 24 4
gpt4 key购买 nike

问题是,当值为 nil 时,我需要从负载中完全删除属性 @"unitprice",但如果它在请求中有值,则将其保留在那里。因此 OrderLine 的有效负载相应地如下所示:@{"id":@"orderlineId", @"unitprice":@"unitprice"} 或 @{"id":@"orderlineId"} 请注意映射是一对多的关系。是否有可能做到这一点?非常感谢您的帮助谢谢!/* 请求描述符 */

+(RKObjectMapping*) getSalesOrderMapping:(RKRequestMethod)method {

RKEntityMapping *requestMapping = [RKEntityMapping mappingForEntityForName:@"SalesOrder"
inManagedObjectStore:[RKManagedObjectStore defaultStore]];
RKEntityMapping *orderLinesMapping = [RKEntityMapping mappingForEntityForName:@"OrderLine"
inManagedObjectStore:[RKManagedObjectStore defaultStore]];
requestMapping.identificationAttributes = @[ @"salesOrderId" ];
NSMutableDictionary *attributeMappings = [NSMutableDictionary dictionaryWithDictionary:@{
@"id": @"salesOrderId",
}];
NSDictionary *orderLineAttributeMappings = @{
@"id": @"orderlineId",
@"unitprice": @"unitPrice"
};

[orderLinesMapping addAttributeMappingsFromDictionary:orderLineAttributeMappings];
[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"lines"
toKeyPath:@"salesOrderToOrderLines"
withMapping:orderLinesMapping]];


return requestMapping;
}

enter image description here

最佳答案

在映射上将 assignsDefaultValueForMissingAttributes 设置为 NO。您不应该需要 2 个不同的映射(除非您确实希望在 JSON 中为某些属性包含 nil)。

关于ios - RestKit - 从 RKRequestDescriptor 中排除具有 nil 值的属性映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24443606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com