发布到我的服务器时遇到问题。正在解析每个值,期望我的数组的属性名称不是。
我的服务器期待这样的事情:
{ “位置”:2, “_id”:“517808546b496658c10209”, “产品”:[ { “金额”:3, “总数”:6.6, “名字”:“可乐”, “价格”:2.2 },{ “金额”:1, “总数”:4.0, “名字”:“水”, “价格”:2 } ] }
但是我的客户发送了这个:
{ “位置”:2, “_id”:“517808546b496658c10209”, “产品”:[ 3, 6.6, “可乐”, 2.2, 1, 4.0, “水”, 2 ] }
产品:
@property (nonatomic) NSNumber *_id;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *detail;
@property (nonatomic, assign) float price;
@property (nonatomic, strong) Category *category;
@property (nonatomic, assign) int amount;
@property (nonatomic, assign) float total;
我的代码:
RKObjectMapping *productMapping = [RKObjectMapping requestMapping];
[productMapping addAttributeMappingsFromDictionary:@{@"productId":@"_id",@"amount":@":amount",@"total":@"total",@"price":@"price",@"name":@"name"}];
RKObjectMapping *horecaMapping = [RKObjectMapping requestMapping];
[horecaMapping addAttributeMappingsFromDictionary:@{ @"Id": @"_Id",@"deliverySpotId":@"location"}];
[horecaMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"self.getBasketSet" toKeyPath:@"products" withMapping:productMapping]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:horecaMapping objectClass:[Horeca class] rootKeyPath:nil];
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:baseURL];
[manager addRequestDescriptor:requestDescriptor];
[manager postObject:sharedHoreca path:@"/orders" parameters:nil success:nil failure:nil];
- 更新1-- 我也尝试制作我阵列的NSSET,但这对我没有帮助。 (nsarray to nsset restkit)
答案 0 :(得分:0)
self.getBasketSet
关键路径让我暂停 - 返回的是什么?如果您的sharedHoreca
对象返回响应指定键路径的NSArray
个对象,那么它应该按照您的预期进行...